Visual inspection of python profiler output with gprof2dot
Ever wondered how to make a beatiful and powerful call graph from your python profiler? I have found that there is no need to install heavyweight tools like KCachegrind or even worse, buying expensive IDEs. The solution is simple.
Wrap the part of code you want to inspect (here a bogus function with name my_super_slow_function()
) with the following call:
Then run your Python code as always. This result in a "profile.stat"
file that you can analyze using graphviz and the wonderful tool gprof2dot
.
First install graphviz (on Ubuntu a simple thing):
then install gprof2dot
from the PyPi repositories:
Finally you can convert the profile.stat
file into a beatiful call graph.
Take a look at the output file. Isn’t it great?