How to use the tuna.main.TunaError function in tuna

To help you get started, we’ve selected a few tuna examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / tuna / tuna / main.py View on Github external
# import time:     11988 |      20571 | encodings
    # import time:       700 |        700 | encodings.utf_8
    # import time:       535 |        535 | _signal
    # import time:      1159 |       1159 | encodings.latin_1
    # [...]
    # ```
    # The indentation in the last column signals parent-child relationships. In the
    # above example, `encodings` is parent to `encodings.aliases` and `codecs` which in
    # turn is parent to `_codecs`.
    entries = []
    with open(filename) as f:
        # filtered iterator over lines prefixed with "import time: "
        try:
            line = next(f)
        except UnicodeError:
            raise TunaError()

        for line in f:
            if not line.startswith("import time: "):
                logging.warning(f"Didn't recognize and skipped line `{line.rstrip()}`")
                continue

            line = line[len("import time: ") :].rstrip()

            if line == "self [us] | cumulative | imported package":
                continue
            items = line.split(" | ")
            assert len(items) == 3
            self_time = int(items[0])
            last = items[2]
            name = last.lstrip()
            num_leading_spaces = len(last) - len(name)
github nschloe / tuna / tuna / main.py View on Github external
def read(filename):
    try:
        return read_import_profile(filename)
    except (TunaError, StopIteration):
        pass

    # runtime profile
    data = read_runtime_profile(filename)
    return data