Profiling programs written in C or C ++

What would you suggest the best tool for profiling C / C ++ code and determine which parts take the most time. Currently, I just rely on magazines, but of course the information is not accurate, because unnecessary delays are introduced.

Preferably, the tool will also be able to detect / suggest areas that can be optimized if such a tool exists.

Platform: Linux

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

+4
source share
9 answers

I can heartily recommend callgrind in combination with KCachegrind .

+9
source

"gprof" in linux / freebsd is a fairly simple and efficient tool for determining which routines run cPUs at runtime. It gives both a nested and a flat profile of functions. It gives you the percentage of CPU time spent by each function that is performed while the profiler is running, as well as the percentage taken inside the function itself and the percentage taken by its child functions. This will help you to easily separate disturbing functions.

+5
source

I made a good experience using the profiler from Microsoft Visual C ++, there are other external programs such as Intels VTune , but most of them are not free.

+2
source

Depends on the platform. If you use MSVC, some versions have a built-in profiler. AMD and Intel also have profilers (CodeAnalyst and VTune).

On Linux, the only thing I used was gprof, but I know there are others (and I think AMD or Intels may be available on Linux versions as well)

And, of course, the whole Valgrind package is also useful. Some tools, such as callgrind or cachegrind, can provide you with a lot of performance information.

+1
source

There are many good profiling tools like Quantify or KCachegrind. One of the problems with these tools is that they slow down runtime performance, so on some large systems they may not scale well.

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

If you are always in the same part of the code, you have found where you are likely to spend most of the time.

+1
source

You obviously want two things:

  • Profile your code and measure it.

  • To identify areas that can be optimized.

These are different problems. They are not the same, despite what they told you.

For problem (1), many good profilers will be proposed.

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

Look at here

+1
source

I am going to go with gprof / oprofile if we are talking about the UNIX world.

You need to recompile the application (at least with gprof).

Gprof

Orprofile

+1
source

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

0
source

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

0
source

All Articles