Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to visualize profiler output as graph using Gprof2Dot

📅 2013-Jun-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ dot, gprof, gprof2dot, pstats ⬩ 📚 Archive

Output of GProf2Dot

Profilers can be used to profile your code and dump the output to a file. Different profilers use different formats, like gprof used by GProf (used for C/C++ code) and pstats used by cProfile (used for Python code). GProf2Dot is a Python tool that can be used to visualize such profiler output as a colorful directed call graph that makes it easy to understand the statistics. The graph is produced in the DOT format, which can be viewed or converted to an image file.


The easiest way is to install from the Python Package Index (PyPI):

$ sudo pip install gprof2dot

Else, you can also download the file and place it in a directory which is on your path.


For GProf, you can pipe the output to this tool. It will convert the call graph profiling data to a dot graph. You can redirect this output to a dot file.

$ gprof foo | >

For cProfile, you can dump the output to a pstats file and read that into GProf2Dot:

$ python -m cProfile -o foo.stats
$ gprof2dot foo.stats -f pstats >

By default, GProf2Dot assumes the profiling statistics are in the gprof format. If you pass any other format without indicating the format, you get this error:

$ gprof2dot foo.stats  >
error: unexpected end of file

Tried with: GProf2Dot 2015.02.03 and Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧