Monday, March 08, 2010

Picture = 1024 words

Most of the time, I need a pictorial representation of call graphs to understand the profiler information with more clarity. Usually I use it to ensure that I am using the memory and CPU efficiently and which part of the code I need to optimize to get the best bang per buck. In my laptop, I use valgrind to generate the call graph and KCachegrind to study the visual representation of call graph. When I use Solaris, I use the dtrace script given by my friend here along with graphviz to visualize the call graph.

But recently at work, I got a Fedora system for which I was not the system administrator. The system administrator was reluctant to install valgrind or KCachegrind stating the fact that gprof was installed in the system and I could use that. Only thing I dislike about gprof is the fact that I have to recompile my C source codes with an additional option. But other than that, I have nothing against it. Even then, I needed a visual representation and so I started writing yacc and lex to parse the gprof output and create a graphviz file. Before getting deep into it, I noticed that there is something called gprof2dot - a python code that converts gprof output to a dot file.

gprof2dot does the magic that I wanted. Interestingly, it has support for an array of profilers including valgrind. The source code is open and it is object oriented and well organized. Each profiler is parsed by a separate class (like GProfParser) that implements a common Parser class. So we can easily plugin our code for our profiler's output (if we use a different profiler). Only thing that could have been done differently is that the author could have used GvGen dot file generator library instead of creating it as a generic output file.

Now all I need to do is to use gprof2dot to generate the dot file that I can parse through graphviz. Or alternatively I can modify the source code to use PyDot library and generate the PNG file in a single shot. Once again the world is saved by free and open source software!

No comments:

Post a Comment