Quick VTune Tutorial

VTune kicks butt. It's a sampling profiler made by Intel, so it can't give you a call trace, but it's so low-impact that you can profile anything, and it'll tell you where you're spending all of your time on a microscopic level. Even if you're looking for macroscopic efficiencies, this information is very useful; a little source grepping will give you the overview once guided by VTune output data.

Here's a quick run-down for getting useful data out of VTune:

  • Make sure you profile the release mode version of your program :-)
  • Build your binary with full program database debug information (this is not default for MSDEV)
  • Start VTune. Choose the "Wizard" for starting a profiling project.
  • In the wizard, make sure you're using a sampling session for a Win32 app. Specify your binary (.EXE) file. Finish the wizard, but do not start the profile.
  • Once the wizard is finished, open the Options dialog. Click Sampling Sessions. Say that you want to wait for 10 seconds before starting, and then sample for 20 seconds (tune as necessary).
  • Click Advanced. Type in the time "0.1 milliseconds" and increase the memory range to at least 2048 kilobytes of sample memory.
  • Open the Automation options page. Click "Do not start a program" (the last option).
  • Close the options page. Your project is now set up.
  • Start your program the normal way (either from the command line, from MSDEV, or by double-clicking it).
  • Once the program is getting to the point you want to profile, switch back to VTune. Click the little "Play" button in the toolbar. VTune will make its window smaller, and begin a 10-second countdown.
  • Use the 10-second countdown to switch back to your application and start doing what you want to be profiling.
  • When VTune has counted down, it will profile the entire system in the background. When it's done profiling (20 seconds after starting after the countdown) you should quit your application to give VTune all the CPU time.
  • The VTune GUI and analyzer parts are written in Visual Basic.
  • You will finally get a view of two windows: the Modules view (listing how much time was spent in each DLL/EXE file) and the Hot Spots view for your application.
  • Make sure that the Hot Spots view for your application shows the right .pdb file name at the bottom of the window. If not, type in the right path, and press enter, and wait while VTune regenerates the data. This is KEY to get source view.
  • Switch to source view, and start zooming/double-clicking to explore. Have fun!

At point 15, it's often useful to export the Function View and the Class View to comma-separated data files that can open in Excel, and then you can sort them and massage them in there to generate good data suitable for public presentation.