Pages

Friday, August 25, 2017

Installing VSPerf in a server environment

Troubleshooting code issues in production is always a challenge, without affecting the performance of the application. Usually we are tied to application logging or tools like the ones from Sysinternals to have a quick pick under the hood. In this article I am going to introduce VSPerf, a component from Visual Studio with which you are able to profile applications on Windows 2012/Windows 8 or later.

VSPerf is part of the Visual Studio kit (I will be using Visual Studio 2015), which uses the ETW technology and captures stack traces from an application. This is a great alternative to Windows Performance Recorder(WPR) and Windows Performance Analyzer(WPA). Within this trace, you are able to look at the call stack of the application(s) during the period you capture the trace. You can easily find what functions are consuming CPUs and in comparison to WPR, you are also able to find the parent function which is calling the problematic function (there are situation where a function is called multiple times from different places in your code).Before installing this, take into account eventual performance issue that might occur while running a trace.

In the next steps I will consider two machines:
  • The server: where we will do the capture of the trace without installing Visual Studio (this article)
  • The client: this is where we are going to open and analyze the trace (next article)

Installation:

  1. Get a Visutal Studio 2015 Installation Package and mount the iso
  2. In the ISO you will find a folder "Standalone Profiler". There you will find "Profile_Setup_x64.exe" for 64-bit operating system and "Profile_Setup_x86.exe" for 32-bit operating system
  3. Copy the file "Profile_Setup_x64.exe"  and move it to the server 
  4. Launch the installation (no reboot is required)
  5. You will find the installation for x64 systems will be under: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools" (for 32-bit systems the path would be "C:\Program Files\Microsoft Visual Studio 14.0\Team Tools\Performance Tools")
More information about the tools which came with the Visual Studio Profiler can be found here: https://msdn.microsoft.com/en-us/library/ms182402.aspx.  Unfortunately there is not much more documentation other than listing the parameters. 


Capturing the data Running the trace:

For capturing the trace we do not need the symbols (these are needed later while analyzing the trace). Reference for the parameters used:https://msdn.microsoft.com/en-us/library/hh977161.aspx
  1. Get the process id for the process you want to capture (for example in Task Manager under the Details tab, find the process. Under the column PID you will find the process id)
  2. Open a CMD prompt with run as administrator
  3. Change the directory to the VSPerf folder:"cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools"
  4.  To start the trace and attach to the process id 2920 run the following command "vsperf.exe /attach:2920 /file:C:\temp\trace1".
  5. During this time you will see in the path specified (C:\temp) that you have two files: trace1.etl and "trace1.kernel.etl". These are files created during the capture. While stopping the trace an other intermediate file called "trace1.tmp.merged.etl" will appear. 
  6. To stop the trace run the command run VSperf /detach .
    Attention! If you run VSPerf /stop you will additionally kill the particular process (in our case sqlservr.exe). This action may take some time.|||
  7. In the folder we will find a file "trace1.vspx". This we will use later for analysis. Note that the files "trace1.etl" and "trace1.kernel.etl" and "trace1.tmp.merged.etl" are no longer there. 
  8. Copy the file "trace1.vspx" on the client  machine for analysis (Visual Studio needs to be installed in order to open the file)

No comments:

Post a Comment