Profiling From the Command Line

General Tips:

  • /? is your friend.  Until formal docs are written, you can see all the parameters that each command-line tool accepts by calling the .exe with the /? option. 
  • Do yourself a favor and set up the PATH environment variable.  The "Visual Studio Command Prompt" shortcut has not yet been updated in CTP to include the profiler tools in the path. Sorry.  So you'll need to add the following path yourself: \Program Files\Microsoft Visual Studio 8\Enterprise Developer Tools\Performance Tools
    WARNING: When you add this to the path, especially if you are using tab completion that automagically adds quotes, be sure that all quotes are removed before you set it. Unfortunately, quoting the path can cause Windows to fail to load DLLs in there that the profiler tools need.
  • For advanced users who intend to control instrumentation at the source code level, vsperf.h is included in the ...\Performance Tools\PerfSDK directory, and of course this must be in the INCLUDE path when you build.

Simple Walkthrough for Command-Line Profiling:

Decide what type of profiling you'll use.  Sampling is generally more appropriate for long-running scenarios that generate loads of data.  Instrumentation (trace) profiling is more for when you're ready to narrow down to smaller focus areas and get the fine granularity. Then

  1. Instrumentation only - use vsinstr.exe to in-place instrument your .exe.
    Sampling only - set the environment for managed sampling using vsperfclrenv.cmd (some tips for doing that were blogged about here )
  2. Start the monitor with vsperfcmd.exe.  The -start:sample corresponds to sampling and the -start:trace option corresponds to instrumentation.  An example for trace profiling might be:  vsperfcmd.exe -start:trace -output:MyDogSlowApp.vsp
  3. Run your application (the monitor will be collecting the performance data at this time).  For example, run MyDogSlowApp.exe from the command line.
  4. Shutdown the monitor with vsperfcmd.exe -shutdown (this will also trigger generation of the .VSP file you specified as the output file at start time that will contain the collected data)
  5. Generate a report from the now available .VSP file using vsperfreport.exe.   For example, vsperfreport -summary:all will generate all the different types of reports in .CSV format.  Generation X'rs may enjoy the -xml option for adorning their data with angle brackets.

Hope that helps, keep the feedback coming! 

[ejarvi]