We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

Walkthrough: Command-Line Profiling Using Instrumentation

This walkthrough demonstrates how to profile an application by using command-line tools and instrumentation to identify performance problems.

In this walkthrough, you will step through profiling a managed application, and use instrumentation to isolate and identify performance problems in the application. You will follow these steps:

  1. Profile an application by using the instrumentation method.

  2. Analyze instrumented profiling results to locate and fix a performance issue.

  • Visual Studio Team System

  • Intermediate understanding of C#

  • Intermediate understanding of working with command-line tools

  • A copy of the PeopleTrax Sample (Profiling Tools)

  • To work with the information provided by profiling, it is best to have debugging symbol information available.

Instrumentation is a profiling method by which specially built versions of the profiled binaries contain probe functions that collect timing information at the entry and exit to functions in an instrumented module. Because this method of profiling is more invasive than sampling, it incurs a greater amount of overhead. Instrumented binaries are also larger than debug or release binaries and are not intended for deployment.

NoteNote:

Do not send instrumented binaries to your customers. Instrumented binaries can contain several risks. The binaries include information that makes your application easier to reverse engineer, as well as security risks.

To profile an application by using the instrumentation method

  1. Open a command prompt window. If necessary, add the profiler tools directory to your PATH environment variable. The path is not added at installation.

    32 bit computers

    On 32 bit computers, the default profiler tools directory is

    \Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools.

    64 bit computers

    On 64 bit computers, specify the path according to the target platform of the application to be profiled.

    To profile 32 bit applications, the default profiler tools directory is

    \Program Files (x86)\Microsoft Visual Studio 9.0\Team Tools\Performance Tools

    To profile 64 bit applications, the default profiler tools directory is

    \Program Files (x86)\Microsoft Visual Studio 9.0\Team Tools\Performance Tools\x64

    For example, to add the profiler directory to PATH on a 32 bit computer, type

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

  2. To profile a managed application, type the following command to set the appropriate environment variables:

    VsPerfCLREnv /traceon

  3. To instrument the application that you want to profile, type the following command:

    VSInstr PeopleTrax.exe

    Note   By default, VSInstr saves a non-instrumented backup of the original file. The backup file name has the extension .orig. For example, the original version of "MyApp.exe" would be saved as "MyApp.exe.orig."

  4. To start the profiler, type the following command:

    VsPerfCmd /start:trace /output:Report.vsp

  5. After you start the monitor process in trace mode, run the instrumented version of the PeopleTrax.exe process to collect data.

    The PeopleTrax application window appears.

  6. Click Get People.

    The PeopleTrax data grid populates with data.

  7. Click Export Data.

    Notepad starts and displays a new file that contains a list of people from the PeopleTrax application.

  8. Close Notepad, and then close the PeopleTrax application.

  9. Shut down the profiler. Type the following command:

    VSPerfCmd /shutdown

  10. When profiling managed applications, use the following command to reset the environmental variables:

    VSPerfCLREnv /off

  11. Analyze the results by using one of the following methods:

    • Examine the raw .vsp file the Visual Studio IDE.

      — or —

    • Generate Xml or comma-separated value (.csv) report files by using the command-line tool VSPerfReport.exe. To generate reports for use outside the Visual Studio IDE use the following command:VSPerfReport <dir>PeopleTraxReport.vsp /output:<dir> /summary:all

Show: