0

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.

apxcode
  • 7,696
  • 7
  • 30
  • 41
Ankit Kumar
  • 1,433
  • 1
  • 16
  • 24

2 Answers2

1

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.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
0

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.

user2760375
  • 2,238
  • 2
  • 22
  • 29
  • for some reasons, it's not working on my ubuntu kernel 3.13.0-24-generic. it fails with lot of warnings "stalled-cycles-frontend event is not supported by the kernel" – Ankit Kumar May 08 '14 at 09:14
  • @dreamer is it problem with both profiling tool or you are saying about the particular one profiling tool ?? – user2760375 May 08 '14 at 09:27
  • I think profiler has done the task, if you know which function is performance intensive, then you should be able figure out which statement is taking time if function definition is simple and if it is not then you can use loggers to find out required statement. – Nachiket Kate May 08 '14 at 12:10