views:

157

answers:

6

Hi,

I want to understand how a C++ program that was given to me works, and where it spends the most time.

For that I tried to use first gprof and then gprof2dot to get the pictures, but the results are sometimes kind of ugly.

How do you usually do this? Can you recommend any better alternatives?

P.D. Which are the open source solutions (preferably for Linux or Mac OS )X?

A: 

See the SD C++ Profiler.

Other answers here suggest that probe-oriented profilers have high overhead (10x). This one does not.

Ira Baxter
A: 

In my opinion there are two alternatives (on Windows):

  • Profilers that change the assembly instructions of your applications (that's called instrumenting) and record every detail. These profilers tend to be slow (applications running about 10 times slower), sometimes hard to set up, and often not-free, but they give you the best performance related information. Look for "Ration Quantity", "AQTime" and "Performance Validator" if you want a profiler of this type.
  • Profilers that don't instrument the application, but just look at a running application and collect 'samples' of it. These profilers are fast (no performance loss), often easy to set up, and you can find quite some free alternatives. Look for "Very Sleepy" and "Luke Stackwalker" if you want a profiler of this type.

Although I used commercial profilers like Rational Quantity and AQTime in the past, and was very satisfied with the results, I found that the disadvantages (hard to setup, unexplainable crashes, slow performance) outweighed the advantages.

Therefore I switched to the free alternatives and I am mainly using "Very Sleepy" at this moment.

Patrick
A: 

If you want to look at the structure of your application (who calls what, references, call trees, ...) look at "Understand for C/C++". This application investigates your source code and allows you to query almost everything from the application's structure.

Patrick
sorry, i meant open source applications, thnaks
Werner
A: 

You can try KCachegrind. This is a program that visualizes samples acquired by Valgrind tool called Callgrind. KCachegrind may seem to be not actively maintained, but the graphs he produces are very useful.

pajton
this looks good! I am going to have a try, thanks
Werner
can you give a link on how to get the call graph info from valgrind before using kcachegrind? thanks
Werner
Try something like `valgrind ­­tool=callgrind <executable>`. There are some options that can tune your results, often used include `­­dump­instr=yes ­­trace­jump=yes`. Then just start `kcachegrind` read the stats and have fun:-). HTH
pajton
A: 

Same answer as ---

Mike Dunlavey
A: 

OProfile on Linux works fairly well, actually i like it better than GProf. There are a couple graphical tools that help visualize OProfile output.

kert