Welcome to MSDN Blogs Sign in | Join | Help

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]

Published Thursday, July 29, 2004 4:56 PM by profiler

Comments

# re: Walkthroughs posted

Thursday, July 29, 2004 8:12 PM by Enterprise Performance Tools Team

# re: Profiling From the Command Line

Thanks much!!! I'll give it a go...
Thursday, July 29, 2004 5:21 PM by Adam

# New Team System Blog Posts - 2004-07-29

Thursday, July 29, 2004 9:27 PM by Rob Caron's Blog

# re: Profiling From the Command Line

This seems to work for me. However, I'm not able to get the method names to show up in the reports. The *_FunctionSummary.csv report contains only addresses under the "Function Name" column. I've tried using the -symbolpath switch with no success (the current directory contains all the PDB's):

vsperfreport MyApp.vsp -summary:all -symbolpath:.

The one suspect message I am getting when running vsperfreport is:

Warning VSP2340 : Managed code profiling DLL was not loaded.
Environment variables may not have been set.
A report file MyApp_Header.CSV is generated.
A report file MyApp_FunctionSummary.CSV is generated.
A report file MyApp_ModuleSummary.CSV is generated.
A report file MyApp_CallerCallee.CSV is generated.
A report file MyApp_CallTree.CSV is generated.
A report file MyApp_ThreadSummary.CSV is generated.

Any ideas?

Thanks in advance.
Friday, August 06, 2004 2:32 PM by Adam

# re: Profiling From the Command Line

For managed profiling from the command line you need to set up several environment variables. We provided a script called VSPerfCLREnv.cmd that should be included. Make sure you run this command before you profiling run or we won't be able to resolve any managed symbols!

I'm assuming your app is Managed. Is that correct?
Friday, August 06, 2004 2:41 PM by steve carroll

# re: Profiling From the Command Line

If it is .Net Code as Steve is suggesting, you can check out our blog posting on how to set up the environment for profiling managed code. The environment settings are needed for symbol resolution for managed trace profiling and managed sampling (only when attaching).

Good luck and let us know if this fixes the problem.

Here's the blog link:
http://blogs.msdn.com/profiler/archive/2004/05/25/141843.aspx
Friday, August 06, 2004 3:05 PM by Marc Popkin-Paine

# re: Profiling From the Command Line

Thanks for the quick response. Yes, it is managed. I just tried:

vsperfclrenv /traceon
Enabling VSPerf Trace Profiling of managed applications (excluding allocation profiling).

Current Profiling Environment variables are:
COR_ENABLE_PROFILING=1
COR_PROFILER={b21542ea-98d7-4704-a4c9-73fd1e54203d}
COR_GC_PROFILING=0

It did not seem to make any difference. I am still getting the "Warning VSP2340 : Managed code profiling DLL was not loaded." when I generate the report.

This is my path:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;
C:\Program Files\Microsoft Visual Studio 8\VC\BIN;
C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;
C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;
C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;
C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;
C:\Program Files\Microsoft Visual Studio 8\Enterprise Developer Tools\Performance Tools
Friday, August 06, 2004 3:13 PM by Adam

# re: Profiling From the Command Line

Did you recollect the data again as well or are you still using the old VSP?
Friday, August 06, 2004 3:29 PM by Eric Jarvi

# re: Profiling From the Command Line

Yes. Did it all from scratch.
Friday, August 06, 2004 3:37 PM by Adam

# re: Profiling From the Command Line

Hrm. That's confusing. We have a -debugsymbolpath flag in the new version that helps to track down symbol loading problems, unfortunately that isn't in the version you are working with.

Do you get symbols for any managed apps at all? Can you try creating a trivial hello world console app in the UI, and profile that with instrumentation in the UI. I want to try to rule out a bad CLR installation.
Friday, August 06, 2004 3:53 PM by steve carroll

# re: Profiling From the Command Line

I'm sorry, I should have mentioned this before. I'm trying to use the May CTP "Performance Tools" w/ Beta 1 environment. That may be the cause for the problems (though I thought things were close enough to work).

This is why I can not do this from the IDE. I'll try the same steps w/ an "Hello World" app. on a May CTP machine I have and see if that works...
Friday, August 06, 2004 4:05 PM by Adam

# re: Profiling From the Command Line

If you get the IDE to work for the scenario you want then that would be preferable because it handles all of the confusing environment settings for you and you wouldn't have to worry about any of that. Plus, viewing reports in the UI is much easier on the eyes.

If that doesn't work and you are still getting the warning message about the managed code dll on the command line, let's make sure that everything is being done correctly (ie the target app needs to be run with the correct environment, not the profiler...a common mistake).

Maybe try the command line approach with a simpler managed app to make sure that things are at least working.
vsinstr <application>
vsperfclrenv /traceon
vsperfcmd -start:trace -output:foo.vsp
<application>
vsperfcmd -shutdown
vsperfreport -summary:function foo.vsp
Friday, August 06, 2004 5:13 PM by Marc Popkin-Paine

# re: Profiling From the Command Line

oof. yeah. May CTP bits + Beta 1 is not going to work.
In somewhat more positive news, the next CTP is not too far out and that will be more complete with much more recent core bits.

sorry man. It might work for native code though.
Friday, August 06, 2004 6:16 PM by steve carroll

# re: Profiling From the Command Line

Got it to work! The part I was missing was:

regsvr32 VSPerfCorProf.dll
Thursday, August 12, 2004 7:40 AM by Adam

# Software Information &raquo; Enterprise Performance Tools Team : Profiling From the Command Line

# Profiling in VS 2008 | keyongtech

Sunday, January 18, 2009 12:27 PM by Profiling in VS 2008 | keyongtech
Anonymous comments are disabled
 
Page view tracker