While looking for a straightforward way to visualize python cProfile profiling data I stumbled over the nice tool Gprof2Dot which uses GraphVis to generate nice graphics. I am just writing this down so I don’t forget it, so I’ll skip most detail. An even better alternative to this would be Runsnakerun, which provides an interactive GUI for data exploration. However I could’t use this due to some fuckup in my macports gwPython.

  1. First, generate some profiling data by
    [code]
    import cProfile
    cProfile.run(‘yourfile.py’,’log.cprofile’)
    [/code]
    and don’t forget the compiler directive @cython.profile(True) if you’re running cython extensions.
  2. Secondly, run gprof2dot.py on the generated file, i.e.
    [code]
    python gprof2dot.py -f pstats log | dot -Tpng -o output.png
    [/code]

That’s it. You can probably do more fancy stuff, check the gprof2dot documentation.