Flameprof

0.4 · active · verified Mon Apr 13

Flameprof is a Python library and command-line tool that generates interactive SVG flame graphs from `cProfile` statistics. It visualizes function call hierarchies and their CPU time consumption, offering a compact and understandable alternative to raw `cProfile` output or tools like `gprof2dot`. The current version is 0.4. Releases are sporadic, with major updates occurring infrequently.

Warnings

Install

Imports

Quickstart

First, create a Python script (`my_app.py`) that you wish to profile. Use Python's built-in `cProfile` module to run your application and save the profiling data to a `.prof` file. Then, use the `flameprof` command-line tool to convert this `.prof` file into an interactive SVG flame graph. Open the generated SVG file in a web browser to view the visualization.

# my_app.py
import cProfile
import time

def func_a():
    time.sleep(0.1)

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

def main():
    for _ in range(3):
        func_b()
    func_a()

# Profile the application
profile_file = 'my_app.prof'
cProfile.run('main()', profile_file)

# To generate the flame graph, run in your terminal:
# flameprof my_app.prof > my_app_flamegraph.svg
# Then open my_app_flamegraph.svg in a web browser.

view raw JSON →