Sunday, April 5, 2009

Graphically Visualizing Output from the Python Profiler

Back when I was a teenager just getting my feet wet with programming, I remember sometimes spending hours looking over my code and making incremental changes, trying to figure out why it was slow. Nobody had told me about profilers! These days my first instinct when something is slower than I expect is to try and find some way to profile it, because the bottleneck is probably not where I think it is.

Python's profiler is nice, but mentally grokking the output can be a little obtuse. Thanks to José Fonseca there's a simple and easy way to visualize the output. He's written a script that converts the output from various profilers (including Python's cProfile) into a dot graph. Here's the output from a recent run that shows a single call to deepcopy killing my app's performance:

Using Gprof2Dot on a basic python project is very simple, although you might run into some trouble if you want to use it on Google App Engine. I haven't tried it yet but there's a good response on stackoverflow that might help.

To learn more about Gprof2Dot, visit the Gprof2Dot project page.

Be the first to reply!

Post a Comment

By submitting a comment you assert that it is your own original work and agree to grant a non-exclusive licence to Brandon Thomson to display it on log.bthomson.com.