views:

138

answers:

4

Hey,

I have a C++ program I am trying to optimize. Since I want it to run fast, I am not using a lot of function calls. Most profiling tool I have seen can give you profiling info in a function-call resolution. However, I would like it in a line-by-line resolution. Is there some option like this?

I am using Visual Studio 2010 on Windows.

Thanks.

+2  A: 

Intel Parallel Amplifier should be capable of what you want. If that is what you want:

amplifier

Keynslug
I will try it, thanks
R S
+2  A: 

If you're running with on an AMD processor, CodeAnalyst is free and can do that (at least, in time-based profiling); you can actually "zoom" in and out seeing what is taking the most CPU time from processes to functions down to single assembly instructions.

CodeAnalyst window

However, keep in mind that to get meaningful results to that resolution with time-based profiling you should run the critical part of the code several times, otherwise the statistics you get doesn't have much sense.

By the way, in my opinion you should forget about the less function calls=>faster idea. If the cost of a function call is bigger than its "payload", the compiler should be able to figure out by itself if it's convenient to inline the call, and in some cases even inlining too much can slow down the code.

Matteo Italia
Time-based profiling in CodeAnalyst works with other processors too.
Timo
Uh, good to know, thank you. :)
Matteo Italia
There is a bigger cost to functions than the cycles spent in entering and leaving them. The bigger cost is that they are like a credit card, encouraging you to use them more than might be wise. When this tendency is compounded over a few layers, it doesn't take much laxity of judgement to add up to a significant problem.
Mike Dunlavey
A: 

IMHO, this method is best, for these reasons, and here's an example of a 43x speedup. It's not a well-known technique, except to a small number of people, for one example, and another, and another. You may be surprised that it's very low-tech and manual, but you can't beat the results.

Oh, and by the way, for Visual Studio, LTProf may well be the next best thing. It gives you line-level percents, derived from stack samples taken at random wall-clock times. Don't get sucked in by a lot of fancy UI options or promises of accuracy of timing. Those things don't matter. What matters is that it pinpoints the spots worth optimizing.

Mike Dunlavey
A: 

AQTime is a commercial profiler for Windows and I have found it to work pretty well for both function and line timings. One thing I like about it is that you do not have to fiddle with compiler options or Visual Studio settings -- i.e. you do not need any additional compiler options to enable profiling: All you need to do the profiling is the pdb (symbol) file and the executable. (And yes, you can create a pdb file for your release-compile.)

Martin