17

Can anybody recommend a good code profiler for C++?

I came across Shiny - any good? http://sourceforge.net/projects/shinyprofiler/

andygeers
  • 6,909
  • 9
  • 49
  • 63

11 Answers11

9

Callgrind for Unix/Linux

DevPartner for Windows

Igor Semenov
  • 1,548
  • 9
  • 7
  • The DevPartner link don't point on the product page (it's redirected). I can't find the product page for DevPartner... – Klaim Jun 01 '09 at 13:00
  • Try archived page: http://web.archive.org/web/20070927222542/http://www.compuware.com/products/devpartner/default.htm – Helen Jun 01 '09 at 18:03
7

Not C++ specific, but AMD's CodeAnalyst software is free and is feature-packed.

http://developer.amd.com/cpu/codeanalyst/codeanalystwindows/Pages/default.aspx

moogs
  • 8,122
  • 8
  • 44
  • 60
7

Gprof if you use gcc. It may not be user friendly but still useful.

artificialidiot
  • 5,309
  • 29
  • 27
6

Probably you will be interested in Intel VTune. Rather useful and allows to collect low-level events like cache misses which helps a lot in tuning.

2

If you are running a Premium version of VS 2010 then you get a profiler with it.

I've also used a couple of other free ones, but they don't compare to the on MS ships. Useful as a second opinion though.

Community
  • 1
  • 1
graham.reeds
  • 16,230
  • 17
  • 74
  • 137
  • 1
    Actually, at least in VS2008 you don't get a profiler with the Pro edition - you have to get the next one up (Team edition or something like it). – Timo Geusch Oct 27 '08 at 13:28
  • Ah. I've not used VS2008 in anger. Some of us are stuck maintain legacy apps in VC6. – graham.reeds Mar 19 '09 at 13:15
2

Quantify (part of the IBM/Rational PurifyPlus package) is a very good profiler, but not exactly cheap. It is available on several platforms, too - I've used it on Solaris, Windows and Linux.

Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
2

Depends on what you need to do:

  1. Measure, so you can do regressions testing to see if changes in performance happened.
  2. Find reasons for suboptimal performance and optimize them.

These are not the same.

For 1, use one of the recommended profilers.

For 2, the profiler I much prefer is one you already have:
http://www.wikihow.com/Optimize-Your-Program%27s-Performance
To see how this goes, check this out.

For C++, as for C# and any language that encourages layers of abstraction, those layers may or may not be good from a software engineering standpoint, but they can kill performance. Every method call is a detour in the execution of your program, and the style encourages you to nest those things, sometimes needlessly. Also the style discourages you from knowing or caring what goes on inside them. You may find them creating and deleting objects underneath at a rate and level of generality far beyond what your application really needs.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • More often than not, the addition of a function call on the stack will not decrease performance. This is usually one of the many traps that people fall in to when prematurely optimizing their code. – Jared May 26 '09 at 18:38
  • Hi Jared. The problem is not the cost of a function call, which is negligible. The problem is the psychology that calls, once written, are absolutely essential. Here's how it shows up: in big software, random samples of the stack can easily be 10-30 layers deep. If any one of those 10-30 calls isn't absolutely necessary, it's removal saves as much time as its residence time fraction on the stack. Another way to put it is, if at any level there are roughly 1.5 times as many calls as absolutely necessary, & that happens at multiple levels, you can see how the slowdown is exponential. – Mike Dunlavey May 26 '09 at 18:58
  • ... another way to put it: optimizers sweat bullets to shave a few low-level instructions like add, move, jump, etc. If they could also do a good job of shaving call instructions, think of the awesome savings. But, for better or worse, that's not the compiler's job, it's ours. – Mike Dunlavey May 26 '09 at 19:12
  • ... sorry, can't resist. Another way to put it is function calls are at the heart of the powerful concept of abstraction. The price of that power is that they tempt us powerfully to make mountains out of molehills. We programmers haven't really learned how to resist that temptation. – Mike Dunlavey May 26 '09 at 19:17
  • 1
    ... yet another way to put it :-) A function call is like a credit card. What is the cost of a credit card? Some plastic, some processing, some marketing - maybe a dollar. The TRUE cost is it's so easy to use that you spend more than you can afford. Multiply this over several layers, and you can see the problem. – Mike Dunlavey Jun 01 '09 at 12:37
2

AQtime (for Windows)

Helen
  • 87,344
  • 17
  • 243
  • 314
0

If you have access to a Mac, then I recommend using Shark from the CHUD tools.

oz10
  • 153,307
  • 27
  • 93
  • 128
0

You can use the analyzer that´s in Sun Studio 12 on Linux or Solaris. Itś free. http://developers.sun.com/sunstudio/index.jsp

tpgould
  • 1,746
  • 10
  • 10
0

If you cannot locate DevPartner it is because we've moved under new ownership. Check us out on the Micro Focus website: http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx. Shameless plug: I work on the DevPartner team. Our long awaited 64-bit versions of BoundsChecker and C++/.NET profilers ship on February 4, 2011. We've changed our pricing model so you can choose either the whole suite or just the performance profiler if that's what you need. Please check out the new DPS 10.5 release when it goes live!

Matt Schuetze
  • 1,112
  • 8
  • 9