Fog Creek Software
Discussion Board

Code Analyzers/Profilers

Does anyone have any recommendations for code analyzers/profilers C++/VB? 

I'm trying out the demo version of VB Watch/Project Analyzer and have already tried Intel's V-Tune for C++.  I know Joel reviewed Compuware's DevPartner? in his article in Programmers Paradise.  Sounds like a nice tool. 

I'm thinking these will (and have already) helped me catch some unnoticed quirks in my code.  Does anyone use these tools on a regular basis? If so what features/functions do you use and how do you use it efficiently?

Dave B. (
Friday, May 30, 2003

Different profiles work in different ways, which is worth understanding.

I've been very happy with Numega TrueTime (part of DevPartner) for profiling C++.  It integrates directly with the backend of the C++ compiler to instrument the code.  On the plus side this seems to be the best technique.  On the downside it can add a long time to the compile and often ties the version of the profiler to a specific compiler version (most of my experience with it was under VC7).

Quantify from Rational (I think ..) takes the approach of instrumenting the code based on the symbol file generated by the compiler (PDB).  This doesn't add any time to the compile phase, but adds a new instrument phase.  I've never been as happy with the results it achieves.

Depending how you use it Intel's VTune doesn't instrument the code at all.  Instead it uses sampling techniques: check the program counter every millisecond to see were the program is (worked out from the symbol file).  There are a lot of settings to play with, and you can also look at all sorts of obscure chip and memory architecture metrics (cache misses, pipeline stalls, ...)

It seems to work well, and has the advantage of imposing at lot less overhead on the system.  Invasive profilers tend to slow the application being profiled down substantially (in our case >10x) which can cause problems of its own.

V-Tune and DevPartner complement each other, but if I could only afford one then I would go with DevPartner.

Rob Walker
Friday, May 30, 2003

I can't believe that more people don't use these tools more often.  (Unless they just aren't saying so.) 

Using the code analyzers I have been able to identify and make about 2 - 3 improvements per 1000 lines of code.  And using the profilers I am able to keep my code executing at a reasonable pace.  I like the call graphs because they help me to identify redundancy and other nuances.

As for using them efficiently, I think it's a matter of writing the code first and manually debugging it, then use the code analyzer to see what you've missed. Simply because you can't rely on the code analyzer to catch everything.  And of course you probably know that there is no substitute for good design/documentation/coding. (i.e. Don't code a routine and run it throught analyzer/profiler, code the whole unit and then run it through.)

As for the best one out there I think DevPartner is the best, but then it is the only one I have used.

Anyway, my $0.02, good luck.

Saturday, May 31, 2003

> I can't believe that more people don't use these tools more often.

I found that MSVC's sampling profiler was too inaccurate to be useful. For example, running it on an image processing library which runs through 20KLOC in a second, something which samples every millisecond doesn't tell me how to optimize the bottleneck: will barely even tell me where the bottleneck is (two identical 5-minute profiling runs would come up with different results). MSVC's profiler also didn't seem to work on multi-threaded code. It also didn't let me profile all the DLLs in an application simultaneously.

Similarly, an intrusive profiler made my code so slow that the code wouldn't work any more: couldn't use it to profile the code which drives a real-time fax session, because it made the code run so slowly that the fax session aborted with a timeout.

I ended up writing my own profiling code to hook into my application; I tried to not perturb the performance of the code which was being profiled, for example by storing profiler results within in-process RAM and saving them after the profile run was finished; by enabling specific hooks I could control which subset of the application I was profiling.

Christopher Wells
Saturday, May 31, 2003

Christopher, the MSVC profiler (I'm familiar with version 6) takes a little work to get right but can be highly effective when used right. 

It's not integrated very well into the IDE.  For example, to profile multiple DLLs, there's a text box on the profiler dialog that you have to fill with the right switches and DLL names. 

You might want to take a look at the .bat files located in "<install directory>\VC98\Bin" and read the docs on the command line usage. 

Saturday, May 31, 2003
Project Analyzer is an excellant tools.

Sunday, June 1, 2003

I do a lot of C++ coding both under Linux / Unix and MS environments.

Most of the profiling / code analysis I have done has been under Linux.

I have found the profiling capabilities of GCC really useful for testing - I can run a unit test sequence and then examine the coverage of the unit tests to ensure that my tests cover 100% of my code.

Valgrind (memory leak checker) is a serious piece of kit. It doen't have as nice an interface as Rational's Purify, but I have certainly found it much easier to use (but I have only used a Linux version of Purify).

best regards

Monday, June 2, 2003

*  Recent Topics

*  Fog Creek Home