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 gprof2dot.py 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 | gprof2dot.py > foo.dot
For cProfile, you can dump the output to a pstats file and read that into GProf2Dot:
$ python -m cProfile -o foo.stats foo.py $ gprof2dot foo.stats -f pstats > foo.dot
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 > foo.dot error: unexpected end of file
Tried with: GProf2Dot 2015.02.03 and Ubuntu 14.04