Python profiling tools
Posted on July 1, 2026 by Ben Dickson.
For Python, my most commonly used tool is gprof2dot. Run a snippet of code with cProfile, like
import cProfile
cProfile.run("""import thing; thing.go()""", filename="/tmp/example.prof")
Then convert the .prof file to a graphviz call graph using
python gprof2dot.py -f pstats /tmp/example.prof | dot -Tpng -o example.png
It makes it easy to see things that take most time, and importantly to see how many times they are called, and what called them. Since it can work of the builtin cProfile, it's also easy to capture profiling data when working inside thirdparty applications.
It's also nice in that it works with other profiler outputs like the Linux perf and callgrind, so I've used it to profile Rust and C++ code.
Other tool I found recently which seems useful is pyinstrument which has it's own tracing tool, and generates interactive flamegraph as a webpage.