While Visual Studio 2005 has an integrated add-in for profiling managed code, VSProfiler is a stand-alone profiler for managed code.
It can be used to profile production systems or machines where Visual Studio can't be installed.
VSProfiler - vs_profiler.exe can be found on Visual Studio installation disc in wcu\profiler folder.
Executing the vs_profiler.exe installs required tools in Visual Studio installation folder like :
D:\Program Files\Microsoft Visual Studio 8\Team Tools\Performance Tools
VSProfiler supports two kinds of profiling :
- Sampling : Where the profiled application is analyzed and data is captured at fixed intervals e.g. after every 5 seconds performance data like CPU usage, memory usage, call graph, etc is gathered.
- Instrumentation/Trace : Application is profiled continuously through out the application lifetime. This is definitely more accurate but slows down the application performance during profiling and the size of output data is generally huge.
In this post i will demonstrate the steps to profile pre-built assemblies of asp.net web application using instrumentation.
- Run VSPerfCLREnv /globaltraceon. This will setup the environment to load profiling infrastructure. Reboot is required after this.
- Insert the instrumentation code in each of the assemblies you want to profile. Use the following command :
vsinstr <assembly name> Make sure use the debug build for these assemblies and generate pdb files also.
- Start the performance monitor using following command :
vsperfmon /TRACE /OUTPUT:[outputfile].vsp /USER:"[ASP.NET worker process user]"
- An important tip here .. make sure the worker process is already not started else it won't get registered with profiler and no data will be collected.
- Start using your web application. You will see a message on profiler windows regarding registration of worker process.
- Once you are through with application navigation, start another command window and execute the following commands:
- A vsp file is created which contains all the data for analysis. While Visual Studio is required to view vsp file, following command generates two csv files using vsp file *Header.csv and Function_summary.csv which can be used for analysis without Visual Studio.
vsperfreport [outputfile].vsp /SUMMARY:FUNCTION /PACKSYMBOLS
- Opening vsp file in VS2005 you will be able to see following :
- Performance Report Summary showing Most called functions, Functions with most individual work, Functions taking longest.
- How the various functions performed.
- functions call graphs.
- If you are through with profiling make sure to reset the environment for switching off profiling infrastructure by executing following command :
Reboot is required after this.