Export (0) Print
Expand All

How to: Profile Services

Visual Studio 2005

A service is a program that runs in the background under Windows NT 4.0, Windows 2000, Windows XP Professional, or Windows Server 2003. Examples include the Telnet service and the ASP.NET service. A service cannot be run from within Visual Studio; it must run within the context of the Services Control Manager. Because of this, profiling a service is not as straightforward as profiling other Visual Studio application types.

NoteImportant

You must install the service before you can profile it. For more information, see How to: Install and Uninstall Services.

You can profile a native service by using VSPerfCmd, VSInstr, and VSPerfMon command line tools. To profile managed services, you must follow additional steps that are required to set up the common language runtime environment. The following procedures list the process you should follow.

To profile a managed service using sampling

  1. Install your service. For more information, see How to: Install and Uninstall Services.

  2. Open a command line window. At the command prompt, run the following command:

    c:\<path>VSPerfClrEnv /globalsampleon 
    

    This will set up the environment variables that you need to profile managed services.

  3. Restart the computer.

  4. Use Service Control Manager to make sure that the service is running after installation. For more information, see How to: Start Services.

  5. Next, run the following command:

    c:\<path>VSPerfCmd /start:sample /output:filename
    

    Profiler starts in sampling mode. The /output option creates a .VSP file to store performance data.

    NoteImportant

    You might have to include the /USER option to allow client access to the monitor from the specified account.

  6. Next, run the following command to attach the process:

    c:\<path>VSPerfCmd /attach:pid | name 
    

    The /attach option attaches the service using process identifier (pid) or process name (name).

  7. To complete the session, detach the process by running the following command:

    c:\<path>VSPerfCmd /detach:pid | name
    

    You can also stop the service or the process hosting the service in a multi-service process.

  8. Next, run the following command to shut down the profiler:

    c:\<path>VSPerfCmd /shutdown
    
  9. The /shutdown option forces the VSPerfCmd tool to wait for monitored applications to shutdown and then shuts down VSPerfMon.exe and wait for the shutdown completion.

  10. Next, use the following command to remove the environment variables that are required to profile managed services.

    C:\<path>VSPerfClrEnv /globaloff 
    
  11. Restart the computer.

To profile a managed service using instrumentation

  1. Instrument your service using VSInstr.exe tool. For information about see, VSInstr.

  2. Install your service. For more information, see How to: Install and Uninstall Services.

NoteNote

Service should be configured as "manual." It should not start automatically. You will start the service in step 6.

  1. Open a command line window. At the command prompt, run the following command:

    c:\<path>VSPerfClrEnv /globaltraceon 
    

    This will set up the environment variables that are required to profile managed services.

  2. Restart the computer.

  3. Next, run the command following command:

    c:\<path>VSPerfCmd /start:trace /output:filename
    

    Profiler starts the instrumentation mode. The /OUTPUT option creates a .VSP file to store performance data.

    NoteImportant

    You might have to include the /USER option to allow client access to the monitor from the specified account.

  4. Use Service Control Manager to make sure that the service is running after installation. For more information, see How to: Start Services.

    NoteImportant

    When the service starts and the performance monitor is running, the service will attach to the performance monitor. If the service is already running when the performance monitor is started, the opportunity to attach is missed.

  5. To end instrumentation, stop the service.

  6. Next, run the following command:

    c:\<path>VSPerfCmd /shutdown
    

    The /shutdown option forces the VSPerfCmd tool to wait for monitored applications to shut down and then shuts down VSPerfMon.exe and waits for the shutdown completion.

  7. Next, use the following command to remove the environment variables that are required to profile managed services:

    c:\<path>VSPerfClrEnv /globaloff
    
  8. Restart the computer.

Community Additions

ADD
Show:
© 2014 Microsoft