4

What would you suggest the best tool to profile C/C++ code and determine which parts are taking the most time. Currently, I'm just relying on logs but ofcourse the information is not accurate since unnecessary delays are introduced.

Preferrably, the tool would also be able to detect/suggest areas which could be optimized, if such tool exist.

Platform: Linux

The application shall be used on an embedded environment so it should be lightweight and external (not a plugin on some IDE).

1
  • Linux. I'll be using it on an embedded environment so it should also be lightweight and external (not a plugin to some IDE).
    – green_t
    Mar 17, 2009 at 13:16

9 Answers 9

9

I can heartily recommend callgrind in combination with KCachegrind.

1
  • 1
    kcachegrind is easily the best visualization i've seen, but beware that if you have the source, gprof will be much, much faster, and if performance is absolutely critical or you'd like to take a closer look at hardware performance counters to find pathologies, OProfile is likely the way to go.
    – Matt J
    Apr 14, 2009 at 6:39
5

"gprof" on linux/freebsd is a quite simple and efficient tool to identify which routines are hogging the cPU at runtime. It gives both nested and flat profile of functions. It gives you the percentage of CPU time taken by each function executed during the runtime of the profiler, and also the percentage taken within the function itself, and the percentage taken by its child functions. That helps you easily segregate the offending functions.

1
  • That's all I needed last time I needed to improve performance. Mar 17, 2009 at 13:31
2

I've made good experiences using the profiler from Microsoft Visual C++ , there are other external programs like Intels VTune, too, but most of them aren't free.

1

Depends on the platform. If you're using MSVC, some versions of it has a profiler built in. AMD and Intel both have profilers available as well (CodeAnalyst and VTune).

On Linux, the only one I've used is gprof, but I know there are others (and I think AMD's or Intels ones may be available in Linux versions too)

And of course the entire Valgrind suite may be helpful too. Some tools like callgrind or cachegrind can give you a lot of information about performance.

1

There are many good profiling tools for this like Quantify or KCachegrind. The one problem with these tools is that they slow down the run time performance so on some large systems they may not scale well enough.

Sometimes it is enough to just run in the debugger and press ctrl-c, look at the stack trace and repeat this maybe 4 times.

If you are always in the same part of the code then you have found where you are probably spending most of the time.

1
  • Bingo. In particular, you should look for call sites that are on multiple call stack samples. Mar 17, 2009 at 13:40
1

You clearly want two things:

  1. To profile your code & measure it.

  2. To detect areas that could be optimized.

These are different problems. They are not the same, in spite of what you may have been told.

For problem (1) many good profilers will be suggested.

For problem (2) profilers help only indirectly.
There is a much simpler and usually more effective technique.

Look Here

1

Im gonna go with gprof / oprofile, if we are talking about the UNIX world.

You do need to recompile your app (at least with gprof).

Gprof

Oprofile

0

If you're on Windows, I suggest AQTime. Supports almost every compiler out there, including .NET, Delphi and VB (and all C++ compilers, of course (; ) and is just the best profiling tool I ever tried. And it's not only a performance profiler.

0

For performance measurements oprofile is a good choice as there exists a user friendly plugin for eclipse in the Linux Tools Project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.