{"id":13460151,"url":"https://github.com/nschloe/tuna","last_synced_at":"2025-05-13T22:05:09.835Z","repository":{"id":37752212,"uuid":"138811196","full_name":"nschloe/tuna","owner":"nschloe","description":":fish: Python profile viewer","archived":false,"fork":false,"pushed_at":"2025-04-04T22:42:54.000Z","size":5741,"stargazers_count":1461,"open_issues_count":26,"forks_count":34,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-29T13:48:46.749Z","etag":null,"topics":["browser","profile","profiler","pypi","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nschloe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nschloe","ko-fi":"nschloe"}},"created_at":"2018-06-27T01:02:01.000Z","updated_at":"2025-04-25T03:21:29.000Z","dependencies_parsed_at":"2024-01-17T07:02:05.287Z","dependency_job_id":"1dcb4ec5-6483-47e1-86c0-a0cba48cce57","html_url":"https://github.com/nschloe/tuna","commit_stats":{"total_commits":332,"total_committers":14,"mean_commits":"23.714285714285715","dds":"0.19277108433734935","last_synced_commit":"8f26fce72642cbb165759fe5a2096aa352f1cbe3"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Ftuna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Ftuna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Ftuna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Ftuna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nschloe","download_url":"https://codeload.github.com/nschloe/tuna/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036817,"owners_count":22003653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","profile","profiler","pypi","python"],"created_at":"2024-07-31T10:00:36.427Z","updated_at":"2025-05-13T22:05:09.784Z","avatar_url":"https://github.com/nschloe.png","language":"Python","funding_links":["https://github.com/sponsors/nschloe","nschloe"],"categories":["Python","python","语言资源库"],"sub_categories":["python"],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/tuna\"\u003e\u003cimg alt=\"tuna\" src=\"https://nschloe.github.io/tuna/logo-with-text.svg\" width=\"50%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003ePerformance analysis for Python.\u003c/p\u003e\n\u003c/p\u003e\n\n[![PyPi Version](https://img.shields.io/pypi/v/tuna.svg?style=flat-square)](https://pypi.org/project/tuna)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/tuna.svg?style=flat-square)](https://pypi.org/pypi/tuna/)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/tuna.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/nschloe/tuna)\n[![Downloads](https://pepy.tech/badge/tuna/month?style=flat-square)](https://pepy.tech/project/tuna)\n\n\u003c!--[![PyPi downloads](https://img.shields.io/pypi/dm/tuna.svg?style=flat-square)](https://pypistats.org/packages/tuna)--\u003e\n\n[![Discord](https://img.shields.io/static/v1?logo=discord\u0026label=chat\u0026message=on%20discord\u0026color=7289da\u0026style=flat-square)](https://discord.gg/hnTJ5MRX2Y)\n\n[![gh-actions](https://img.shields.io/github/actions/workflow/status/nschloe/tuna/test.yml?branch=main\u0026style=flat-square)](https://github.com/nschloe/tuna/actions?query=workflow%3Atests)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\ntuna is a modern, lightweight Python profile viewer inspired by\n[SnakeViz](https://github.com/jiffyclub/snakeviz). It handles runtime and import\nprofiles, has minimal dependencies, uses [d3](https://d3js.org/) and\n[bootstrap](https://getbootstrap.com/), and avoids\n[certain](https://github.com/jiffyclub/snakeviz/issues/111)\n[errors](https://github.com/jiffyclub/snakeviz/issues/112) present in SnakeViz (see\nbelow) and is faster, too.\n\nCreate a runtime profile with\n\n```\npython -mcProfile -o program.prof yourfile.py\n```\n\nor an [import\nprofile](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPROFILEIMPORTTIME)\nwith\n\n```\npython -X importtime yourfile.py 2\u003e import.log\n```\n\nand show it with\n\n```\ntuna program.prof\n```\n\n![](https://nschloe.github.io/tuna/screencast.gif)\n\n### Why tuna doesn't show the whole call tree\n\nThe whole timed call tree _cannot_ be retrieved from profile data. Python developers\nmade the decision to only store _parent data_ in profiles because it can be computed\nwith little overhead. To illustrate, consider the following program.\n\n```python\nimport time\n\n\ndef a(t0, t1):\n    c(t0)\n    d(t1)\n\n\ndef b():\n    a(1, 4)\n\n\ndef c(t):\n    time.sleep(t)\n\n\ndef d(t):\n    time.sleep(t)\n\n\nif __name__ == \"__main__\":\n    a(4, 1)\n    b()\n```\n\nThe root process (`__main__`) calls `a()` which spends 4 seconds in `c()` and 1 second\nin `d()`. `__main__` also calls `b()` which calls `a()`, this time spending 1 second in\n`c()` and 4 seconds in `d()`. The profile, however, will only store that `c()` spent a\ntotal of 5 seconds when called from `a()`, and likewise `d()`. The information that the\nprogram spent more time in `c()` when called in `root -\u003e a() -\u003e c()` than when called in\n`root -\u003e b() -\u003e a() -\u003e c()` is not present in the profile.\n\ntuna only displays the part of the timed call tree that can be deduced from the profile.\nSnakeViz, on the other hand, tries to construct the entire call tree, but ends up\nproviding lots of _wrong_ timings.\n\n| ![](https://nschloe.github.io/tuna/snakeviz-example-wrong.png) |           ![](https://nschloe.github.io/tuna/foo.png)           |\n| :------------------------------------------------------------: | :-------------------------------------------------------------: |\n|                  SnakeViz output. **Wrong.**                   | tuna output. Only shows what can be retrieved from the profile. |\n\n### Installation\n\ntuna is [available from the Python Package Index](https://pypi.org/project/tuna/), so\nsimply do\n\n```\npip install tuna\n```\n\nto install.\n\n### Testing\n\nTo run the tuna unit tests, check out this repository and type\n\n```\npytest\n```\n\n### IPython magics\n\ntuna includes a `tuna` line / cell magic which can be used as a drop-in replacement for\nthe `prun` magic. Simply run `%load_ext tuna` to load the magic and then call it like\n`%tuna sleep(3)` or\n\n```python\n%%tuna\nsleep(3)\n```\n\n`prun` is still used to do the actual profiling and then the results are displayed in\nthe notebook.\n\n### Development\n\nAfter forking and cloning the repository, make sure to run `make dep` to install\nadditional dependencies (bootstrap and d3) which aren't stored in the repo.\n\n### License\n\nThis software is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Ftuna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnschloe%2Ftuna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Ftuna/lists"}