Tuna

0.5.13 · active · verified Thu Apr 16

Tuna is a modern, lightweight Python profile viewer, currently at version 0.5.13. Inspired by SnakeViz, it visualizes Python runtime and import profiles, offering a faster and more accurate alternative by leveraging d3 and bootstrap for its web-based interface. The project maintains an active development status with regular minor updates.

Common errors

Warnings

Install

Imports

Quickstart

Generate a runtime profile using Python's built-in `cProfile` module, saving the output to a file. Then, visualize the profile by running the `tuna` command-line tool with the generated profile file. Alternatively, you can profile import times by redirecting `python -X importtime` output to a log file and viewing it with `tuna`.

import cProfile
import time

def func_a():
    time.sleep(0.1)

def func_b():
    func_a()
    time.sleep(0.05)

def main():
    func_a()
    func_b()

profile_file = 'my_program.prof'
cProfile.run('main()', profile_file)

print(f"Profile saved to {profile_file}. View with: tuna {profile_file}")

# To view import profile (run from terminal):
# python -X importtime -c "import pandas" 2> import.log
# print("Import profile saved to import.log. View with: tuna import.log")

view raw JSON →