def METHOD_NAME(filename: str) -> Profile:
    contract = None
    profile = Profile(filename=filename)
    with open(filename) as fp:
        for line in fp:
            line = _ANSI_ESCAPE_PAT.sub("", line)
            m = _CONTRACT_PAT.match(line)
            if m is not None:
                contract = m.group(1)
                continue
            if contract is None:
                continue
            m = _FUNCTION_PAT.match(line)
            if m is not None:
                function, gas = m.groups()
                profile.contracts[contract][function] = int(gas)
    return profile