gprof2dot

2025.4.14 · active · verified Thu Apr 09

gprof2dot is a Python script that converts the output from various profilers (e.g., cProfile, gprof, Valgrind callgrind, Linux perf, Java HPROF) into a Graphviz dot graph. This allows for visual analysis of performance bottlenecks and call flows within an application. The library is actively maintained with a current version of 2025.4.14, typically releasing updates on a yearly or bi-yearly basis.

Warnings

Install

Imports

Quickstart

To use gprof2dot, first profile your application using a compatible profiler (e.g., Python's `cProfile`). Save the profiling output to a file. Then, use the `gprof2dot` command-line tool to convert this profiling data into the Graphviz DOT language, piping the output to the `dot` command (from Graphviz) to generate a visual graph image (e.g., PNG or SVG).

# 1. Profile your Python code (e.g., using cProfile)
import cProfile
import time

def my_function():
    time.sleep(0.1)
    another_function()

def another_function():
    time.sleep(0.05)

if __name__ == "__main__":
    profiler = cProfile.Profile()
    profiler.enable()
    my_function()
    profiler.disable()
    profiler.dump_stats("output.pstats")
    print("Profile data saved to output.pstats")

# 2. Convert the .pstats file to a .dot graph and render with Graphviz
#    Run this from your terminal after the Python script above:
#    gprof2dot -f pstats output.pstats | dot -Tpng -o output.png
#    (Ensure 'dot' command from Graphviz is in your PATH)

view raw JSON →