Got Visual Studio 2008 Professional, Want Profiling?

Posted by

Visual Studio 2008 Professional doesn't come with the built-in profiler (that's a feature reserved for the Team Suite edition). But that doesn't mean you can't profile your applications! Microsoft actually provides a stand-alone verson of the profiler, which you can use from the command-line.

Obviously, since it's a command-line program, it's not as easy to use as the GUI in Team Suite, but it works, and it's better than nothing. Here's some (very basic) instructions (this is for native profiling, but I understand CLR profiling is also available):

  1. Obviously, you need to download the stand-alone profiler, it's not very big. If you have 64-bit windows, you only need to download the x64 version - it includes both the 32-bit and 64-bit profiler.
  2. The next step is to enable profiling in your C++ application. In the properties, under Linker/Advanced, make sure "Profile" is set to "Enable". It's probably better to do this in Release mode as well...
  3. Open up a command prompt, and set up the path to the profiling tools (it doesn't get added automatically because the path is different depending on whether you want to profile 32-bit or 64-bit). If you install everything to the default path, you can just run:

    set path=%path%;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Team Tools\Performance Tools

    Or if you want to profile a 64-bit application, append "x64" to the path.
  4. Next, you need to instrument your application (I'm assuming you're doing an instrumented profile, sampled profiling is also available). To do that, you use the vsinstr.exe tool, like so:

    cd \path\to\my\program
    vsinstr.exe MyProgram.exe


    This will back up your executable to MyProgram.exe.orig, and spit out the instrumented version as MyProgram.exe.
  5. Use vsperfcmd.exe to start the profiler. You should probably do this from an elevated command-prompt (so it can install the driver). Just run:

    vsperfcmd /start:trace /output:MyProgram.vsp

    This will start the profiler and write it's output to MyProgram.vsp
  6. Run your program as normal. Make sure you let it run for a little while in the part you want to profile (so the slow part drowns out start time, etc)
  7. When your program is finished, use vsperfcmd.exe again to stop profiling:

    vsperfcmd /shutdown

    You should see that it's written out the MyProgram.vsp file.
  8. Finally, you can use vsperfreport.exe to generate .csv files that you can analyze in Excel (or whatever). For example:

    vsperfreport MyProgram.vsp /output:c:\temp /summary:all

    This will output a bunch of files to C:\Temp that you can load into Excel.

I won't go into details of how you can analyze the data (there'll be quite a lot of it!) but if you already understand profiling, it shouldn't be too hard.

As I said, the GUI in Team Suite is clearly better than using the command-line, but in a pinch, this method works, too.

blog comments powered by Disqus