HIPL and gprof

NOTE: I am using Ubuntu Karmic Koala and this worked on it. I am not sure if this will work on other distros or do they need different flags.

You may have a sudden need to profile HIPL code in order to see where time is spent or how many times some functions are called etc. At least I had such a need. I read that gprof is easy to use and it was already supported by HIPL. This is partly true, but I found out that it was not quite that simple.

HIPL already has an configuration option that can be used when profiling (--enable-profiling). This option adds the "-pg" flag needed by gprof but I did not use it since I needed to modify other flags also and -pg in that case was shorter to write than the --enable-profiling string.

Here is the commands to execute in the trunk. Assuming that the code has not been compiled previously. If the code has been compiled previously replace the last command with make clean all.

./configure CFLAGS= -pg -g2 -O2 --disable-privsep

The second command here is the interesting one and it says:

Now, when you execute HIPL daemon (sudo hipd/hipd in trunk) the gmon.out will be written to the folder where the command to start the daemon was issued. The flat profile file can be viewed by executing sudo gprof hipd/hipd gmon.out. For more information on how to use gprof see man gprof.

NOTE: You may end up in situation where the times are all zeroes and the gprof will say that no time accumulated. After searching the web and testing with simple programs I found out that gprof requires that considerable time is spent in the profiled program before the time is accumulated. I temporarily added a loop that prints numbers from 1 to 1000000 with HIP_DEBUG to the source code of HIPL. This is an ugly hack but it worked. You just have to remember to put it somewhere that it is executed. Do not put it into the code you are trying to profile, because it distorts the total time spent in the function.

Did not find a smarter way to do this but it worked for me and I found where the time was spent in the code.

All of these manuals/tutorials are provided as is. They worked for me and that is all the help I give with them, so if I forgot something or there is a typo you can inform me but do not expect me to solve your problems :) Oh and almost forgot, use them at your own risk.