green_t
green_t

Reputation: 3037

Profiling programs written in C or C++

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).

Upvotes: 4

Views: 1216

Answers (9)

lothar
lothar

Reputation: 20209

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

Upvotes: 0

Tom
Tom

Reputation: 45104

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

Upvotes: 1

Mike Dunlavey
Mike Dunlavey

Reputation: 40669

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

Upvotes: 1

Jeroen Dirks
Jeroen Dirks

Reputation: 7877

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.

Upvotes: 1

Harty
Harty

Reputation: 316

"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.

Upvotes: 5

OregonGhost
OregonGhost

Reputation: 23759

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.

Upvotes: 0

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 247969

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.

Upvotes: 1

schnaader
schnaader

Reputation: 49719

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.

Upvotes: 2

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

I can heartily recommend callgrind in combination with KCachegrind.

Upvotes: 9

Related Questions