Question

I have this appplication written in C and it should be tuned to increase the performance. i looked at some of the performance profilers available in Linux and found GNU profiler, valgrind are some of them. The issue is all of them gives only functional level profiling information and not the statement level profiling which i need. Is there any tool that can provide this information.

Was it helpful?

Solution

Compile the code with -g to get debug symbols, and with -O0 so the optimizer doesn't scramble the code.

Then run it under the GDB debugger and, while it is being slow, interrupt it by typing Ctrl-C. It will stop on another thread, so type thread 1 to get to the active thread. Then type bt to display the call stack. Look at it carefully to understand just what it was doing, and why it was doing it, when you stopped it.

Do this a few times, and you will have a very precise idea how it is spending time. That is the random pausing technique, and if you go through the comments there, you will see how well it works. Also, FWIW, I made a short video of it.

As you pointed out, most profilers do not give you line-level information. One I know that gives you a) line-level information, b) inclusive time ("self time" is almost useless), c) on wall-clock time (so you are not blind to I/O) is Zoom. Maybe others can do it, I'm not sure.

Even if a profiler gives you all that, it gives you precious little context, and context is what you need to be able to recognize when the time being spent is actually something you could get rid of. Random pausing gives you complete context. It engages your brain in recognizing what is happening, and most importantly why, rather that just giving you numerical or graphical summaries, and hoping that is enough to find speedups.

When you've squeezed out every cycle you can, and you still see a good fraction of samples terminating in the code that the compiler compiles, then turn on -O3 and let the optimizer do its thing.

OTHER TIPS

perf tool is great way to start for profiling this is link

oprofile is also good one but you'll need root access for that this is the link

if you want to see the per line profiling better to use annotate options .try to use non-strip binary and compile with -g -static flag .is this what you want or the different answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top