How to visualize profiler output as graph using Gprof2Dot

Output of GProf2Dot
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

One thought on “How to visualize profiler output as graph using Gprof2Dot”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s