What's your favorite profiling tool (for C++)

C++PerformanceProfiling

C++ Problem Overview


So far, I've only used Rational Quantify. I've heard great things about Intel's VTune, but have never tried it!

Edit: I'm mostly looking for software that will instrument the code, as I guess that's about the only way to get very fine results.


See also:

What are some good profilers for native C++ on Windows?

C++ Solutions


Solution 1 - C++

For linux development (although some of these tools might work on other platforms). These are the two big names I know of, there's plenty of other smaller ones that haven't seen active development in a while.

Solution 2 - C++

For Linux: Google Perftools

  • Faster than valgrind (yet, not so fine grained)
  • Does not need code instrumentation
  • Nice graphical output (--> kcachegrind)
  • Does memory-profiling, cpu-profiling, leak-checking

Solution 3 - C++

IMHO, sampling using a debugger is the best method. All you need is an IDE or debugger that lets you halt the program. It nails your performance problems before you even get the profiler installed.

Solution 4 - C++

My only experience profiling C++ code is with AQTime by AutomatedQA (now SmartBear Software). It has several types of profilers built in (performance, memory, Windows handles, exception tracing, static analysis, etc.), and instruments the code to get the results.

I enjoyed using it - it was always fun to find those spots where a small change in code could make a dramatic improvement in performance.

Solution 5 - C++

I have never done profiling before. Yesterday I programmed a ProfilingTimer class with a static timetable (a map<std::string, long long>) for time storage.

The constructor stores the starting tick, and the destructor calculates the elapsed time and adds it to the map:

ProfilingTimer::ProfilingTimer(std::string name)
 : mLocalName(name)
{
 sNestedName += mLocalName;
 sNestedName += " > ";

 if(sTimetable.find(sNestedName) == sTimetable.end())
  sTimetable[sNestedName] = 0;

 mStartTick = Platform::GetTimerTicks();
}

ProfilingTimer::~ProfilingTimer()
{
 long long totalTicks = Platform::GetTimerTicks() - mStartTick;
 
 sTimetable[sNestedName] += totalTicks;

 sNestedName.erase(sNestedName.length() - mLocalName.length() - 3);
}

In every function (or {block}) that I want to profile i need to add:

ProfilingTimer _ProfilingTimer("identifier");

This line is a bit cumbersome to add in all functions I want to profile since I have to guess which functions take a lot of time. But it works well and the print function shows time consumed in %.

(Is anyone else working with any similar "home-made profiling"? Or is it just stupid? But it's fun! Does anyone have improvement suggestions?

Is there some sort of auto-adding a line to all functions?)

Solution 6 - C++

I've used Glowcode extensively in the past and have had nothing but positive experiences with it. Its Visual Studio integration is really nice, and it is the most efficient/intuitive profiler that I've ever used (even compared to profilers for managed code).

Obviously, thats useless if your not running on Windows, but the question leaves it unclear to me exactly what your requirements are.

Solution 7 - C++

oprofile, without a doubt; its simple, reliable, does the job, and can give all sorts of nice breakdowns of data.

Solution 8 - C++

The profiler in Visual Studio 2008 is very good: fast, user friendly, clear and well integrated in the IDE.

Solution 9 - C++

For Windows, check out Xperf. It uses sampled profile, has some useful UI, & does not require instrumentation. Quite useful for tracking down performance problems. You can answer questions like:

  • Who is using the most CPU? Drill down to function name using call stacks.
  • Who is allocating the most memory?
  • Who is doing the most registry queries?
  • Disk writes? etc.

You will be quite surprised when you find the bottlenecks, as they are probably not where you expected!

Solution 10 - C++

Since you don't mention the platform you're working on, I'll say cachegrind under Linux. Definitely. It's part of the Valgrind toolset.

http://valgrind.org/info/tools.html

I've never used its sub-feature Callgrind, since most of my code optimization is for inside functions.

Note that there is a frontend KCachegrind available.

Solution 11 - C++

For Windows, I've tried AMD Codeanalyst, Intel VTune and the profiler in Visual Studio Team Edition.

Codeanalyst is buggy (crashes frequently) and on my code, its results are often inaccurate. Its UI is unintuitive. For example, to reach the call stack display in the profile results, you have to click the "Processes" tab, then click the EXE filename of your program, then click a toolbar button with the tiny letters "CSS" on it. But it is freeware, so you may as well try it, and it works (with fewer features) without an AMD processor.

VTune ($700) has a terrible user interface IMO; in a large program, it's hard to find the particular call tree you want, and you can only look at one "node" in a program at a time (a function with its immediate callers and callees)--you cannot look at a complete call tree. There is a call graph view, but I couldn't find a way to make the relative execution times appear on the graph. In other words, the functions in the graph look the same regardless of how much time was spent in them--it's as though they totally missed the point of profiling.

Visual Studio's profiler has the best GUI of the three, but for some reason it is unable to collect samples from the majority of my code (samples are only collected for a few functions in my entire C++ program). Also, I couldn't find a price or way to buy it directly; but it comes with my company's MSDN subscription. Visual Studio supports managed, native, and mixed code; I'm not sure about the other two profilers in that regard.

In conclusion, I don't know of a good profiler yet! I'll be sure to check out the other suggestions here.

Solution 12 - C++

There are different requirements for profiling. Is instrumented code ok, or do you need to profile optimized code (or even already compiled code)? Do you need line-by-line profile information? Which OS are you running? Do you need to profile shared libraries as well? What about trace into system calls?

Personally, I use oprofile for everything I do, but that might not be the best choice in every case. Vtune and Shark are both excellent as well.

Solution 13 - C++

For Windows development, I've been using Software Verification's Performance Validator - it's fast, reasonably accurate, and reasonably priced. Best yet, it can instrument a running process, and lets you turn data collection on and off at runtime, both manually and based on the callstack - great for profiling a small section of a larger program.

Solution 14 - C++

I use devpartner for the pc platform.

Solution 15 - C++

I have tried Quantify an AQTime, and Quantify won because of its invaluable 'focus on sub tree' and 'delete sub tree' features.

Solution 16 - C++

The only sensitive answer is PTU from Intel. Of course its best to use it on an Intel processor and to get even more valuable results at least on a C2D machine as the architecture itself is easier to give back meaningful profiles.

Solution 17 - C++

I've used VTune under Windows and Linux for many years with very good results. Later versions have gotten worse, when they outsourced that product to their Russian development crew quality and performance both went down (increased VTune crashes, often 15+ minutes to open an analysis file).

Regarding instrumentation, you may find out that it's less useful than you think. In the kind of applications I've worked on adding instrumentation often slows the product down so much that it doesn't work anymore (true story: start app, go home, come back next day, app still initializing). Also, with non instrumented profiling you can react to live problems. For example, with VTune remote date collector I can start up a sampling session against a live server with hundreds of simultaneous connections that is experiencing performance problems and catch issues that happen in production that I'd never be able to replicate in a test environment.

Solution 18 - C++

ElectricFence works nicely for malloc debugging

Solution 19 - C++

My favorite tool is Easy Profiler : http://code.google.com/p/easyprofiler/

It's a compile time profiler : the source code must be manually instrumented using a set of routines so to describe the target regions. However, once the application is run, and measures automatically written to an XML file, it is only a matter of opening the Observer application and doing few clicks on the analysis/compare tools, before you can see the result in a qualitative chart.

Solution 20 - C++

Visual studio 2010 profiler under Windows. VTune had a great call graph tool, but it got broken as of Windows Vista/7. I don't know if they fixed it.

Solution 21 - C++

Let me give a plug for EQATEC... just what I was looking for... simple to learn and use and gives me the info I need to find the hotspots quickly. I much prefer it to the one built in to Visual Studio (though I haven't tried the VS 2010 one yet, to be fair).

The ability to take snapshots is HUGE. I often get an extra analysis and optimization done while waiting for the real target analysis to run... love it.

Oh, and its base version is free!
http://www.eqatec.com/Profiler/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOysterDView Question on Stackoverflow
Solution 1 - C++Al.View Answer on Stackoverflow
Solution 2 - C++WeidenrindeView Answer on Stackoverflow
Solution 3 - C++Mike DunlaveyView Answer on Stackoverflow
Solution 4 - C++Matt DillardView Answer on Stackoverflow
Solution 5 - C++MobergView Answer on Stackoverflow
Solution 6 - C++jsightView Answer on Stackoverflow
Solution 7 - C++Dark ShikariView Answer on Stackoverflow
Solution 8 - C++Dimitri C.View Answer on Stackoverflow
Solution 9 - C++user15071View Answer on Stackoverflow
Solution 10 - C++rlerallutView Answer on Stackoverflow
Solution 11 - C++QwertieView Answer on Stackoverflow
Solution 12 - C++Louis BrandyView Answer on Stackoverflow
Solution 13 - C++Shog9View Answer on Stackoverflow
Solution 14 - C++EvilTeachView Answer on Stackoverflow
Solution 15 - C++eliView Answer on Stackoverflow
Solution 16 - C++Fabien HureView Answer on Stackoverflow
Solution 17 - C++Don NeufeldView Answer on Stackoverflow
Solution 18 - C++Michael McCartyView Answer on Stackoverflow
Solution 19 - C++charfeddine.ahmedView Answer on Stackoverflow
Solution 20 - C++CoderView Answer on Stackoverflow
Solution 21 - C++Brian KennedyView Answer on Stackoverflow