How to use tuna - 10 common examples

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 / test / test_tuna.py View on Github external
],
                        "color": 0,
                    },
                    {"name": "d", "value": 4e-06, "color": 0},
                ],
                "color": 0,
            }
        ],
    }

    with tempfile.TemporaryDirectory() as temp_dir:
        filepath = Path(temp_dir) / "test.log"
        with open(filepath, "w") as f:
            f.write(content)

        out = tuna.read_import_profile(filepath)

    assert out == ref, ref
github nschloe / tuna / test / test_tuna.py View on Github external
"name": "b",
                        "value": 2e-06,
                        "color": 0,
                        "children": [{"name": "c", "value": 3e-06, "color": 0}],
                    }
                ],
            }
        ],
    }

    with tempfile.TemporaryDirectory() as temp_dir:
        filepath = Path(temp_dir) / "test.log"
        with open(filepath, "w") as f:
            f.write(content)

        out = tuna.read_import_profile(filepath)

    assert out == ref, ref
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 _add_color(tree, ancestor_is_built_in):
    for item in tree:
        module_name = item["name"].split(".")[0]
        is_built_in = (
            ancestor_is_built_in
            or module_name in built_in
            or module_name in built_in_deprecated
        )
        color = 1 if is_built_in else 0
        if module_name in built_in_deprecated:
            color = 2
        item["color"] = color
        if "children" in item:
            _add_color(item["children"], is_built_in)
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
github nschloe / tuna / tuna / cli.py View on Github external
help="Don't start a web browser (default: do start)",
    )

    parser.add_argument(
        "--port",
        "-p",
        default=None,
        type=int,
        help="Webserver port (default: first free port from 8000)",
    )

    parser.add_argument(
        "--version",
        "-v",
        action="version",
        version="%(prog)s " + (f"(version {__version__})"),
    )
    return parser
github nschloe / tuna / tuna / main.py View on Github external
def render(data, prof_filename):
    this_dir = Path(__file__).resolve().parent
    with open(this_dir / "web" / "index.html") as _file:
        template = string.Template(_file.read())

    return template.substitute(
        data=html.escape(json.dumps(data).replace("
github ChristophAlt / tuna / tuna / __main__.py View on Github external
def main():
    runner = AllenNlpRunner()
    executor = RayExecutor(runner)
    executor.run(sys.argv[1:])
github ChristophAlt / tuna / tuna / __main__.py View on Github external
def main():
    runner = AllenNlpRunner()
    executor = RayExecutor(runner)
    executor.run(sys.argv[1:])
github nschloe / tuna / tuna / magics.py View on Github external
def tuna(line: str, cell: Optional[str] = None) -> HTML:
    ip = get_ipython()  # noqa: F821
    with tempfile.TemporaryDirectory() as tmp_dir:
        prun_fname = f"{tmp_dir}/prun"
        prun_line = f"-q -D {prun_fname}"
        with capture_output():
            ip.run_cell_magic("prun", prun_line, cell if cell is not None else line)
        args = [prun_fname, "-o", tmp_dir, "--no-browser"]
        tuna_main(args)
        return _display_tuna(tmp_dir)