Skip to main content

Visualize Python performance profiles

Project description

tuna

Performance analysis for Python.

PyPi Version PyPI pyversions GitHub stars Downloads

Discord

gh-actions Code style: black code style: prettier

tuna is a modern, lightweight Python profile viewer inspired by SnakeViz. It handles runtime and import profiles, has minimal dependencies, uses d3 and bootstrap, and avoids certain errors present in SnakeViz (see below) and is faster, too.

Create a runtime profile with

python -mcProfile -o program.prof yourfile.py

or an import profile with

python -X importtime yourfile.py 2> import.log

and show it with

tuna program.prof

Why tuna doesn't show the whole call tree

The whole timed call tree cannot be retrieved from profile data. Python developers made the decision to only store parent data in profiles because it can be computed with little overhead. To illustrate, consider the following program.

import time


def a(t0, t1):
    c(t0)
    d(t1)


def b():
    a(1, 4)


def c(t):
    time.sleep(t)


def d(t):
    time.sleep(t)


if __name__ == "__main__":
    a(4, 1)
    b()

The root process (__main__) calls a() which spends 4 seconds in c() and 1 second in d(). __main__ also calls b() which calls a(), this time spending 1 second in c() and 4 seconds in d(). The profile, however, will only store that c() spent a total of 5 seconds when called from a(), and likewise d(). The information that the program spent more time in c() when called in root -> a() -> c() than when called in root -> b() -> a() -> c() is not present in the profile.

tuna only displays the part of the timed call tree that can be deduced from the profile. SnakeViz, on the other hand, tries to construct the entire call tree, but ends up providing lots of wrong timings.

SnakeViz output. Wrong. tuna output. Only shows what can be retrieved from the profile.

Installation

tuna is available from the Python Package Index, so simply do

pip install tuna

to install.

IPython magics

tuna includes a tuna line / cell magic which can be used as a drop-in replacement for the prun magic. Simply run %load_ext tuna to load the magic and then call it like %tuna sleep(3) or

%%tuna
sleep(3)

prun is still used to do the actual profiling and then the results are displayed in the notebook.

Development

After forking and cloning the repository, make sure to run just dep to install additional dependencies (bootstrap and d3) which aren't stored in the repo.

License

This software is published under the GPLv3 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuna-0.5.14.tar.gz (162.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tuna-0.5.14-py3-none-any.whl (160.1 kB view details)

Uploaded Python 3

File details

Details for the file tuna-0.5.14.tar.gz.

File metadata

  • Download URL: tuna-0.5.14.tar.gz
  • Upload date:
  • Size: 162.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuna-0.5.14.tar.gz
Algorithm Hash digest
SHA256 5cfd07e91cb4a5f68536615cad6cf0dbf070ed00d368b781dfbcbb039a0911cc
MD5 c93a1975be06f5c8ec444dbcb32eb666
BLAKE2b-256 3a94aebac851c5d1ff307b92403dba78282ec5c86e25b5f3ab8be67932261663

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuna-0.5.14.tar.gz:

Publisher: release.yml on nschloe/tuna

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tuna-0.5.14-py3-none-any.whl.

File metadata

  • Download URL: tuna-0.5.14-py3-none-any.whl
  • Upload date:
  • Size: 160.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuna-0.5.14-py3-none-any.whl
Algorithm Hash digest
SHA256 aeacaacb0e594dcbe8e879fcb700cefc35350b58d186da11a8660bfab4f7b33b
MD5 25452d594d0b1789ab0a4473ab36a902
BLAKE2b-256 b3832f35ed0bcb6cfc20d932c1f12858c9bf4395d8ab83c83c2eb8aabf338d25

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuna-0.5.14-py3-none-any.whl:

Publisher: release.yml on nschloe/tuna

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page