Profiling Windows NT Services

OverviewHow Do I

Feature Only in Professional and Enterprise Editions   Profiling is supported only in Visual C++ Professional and Enterprise Editions. For more information, see .

This topic provides information about profiling Windows NT service processes.

Use the service sample from the directory samples\sdk\winnt\service (after you install this SDK sample), and follow these steps to get timing information for its service functions:

To profile Windows NT Services

  1. Set necessary environment variables using the System control panel. You will find system environment variables like ComSpec, windir, and Path.

  2. Add two new environment variables:

    __ProfilePBI=<full path of your PBI file>
    __ProfilePBO=<full path of your PBO file>
    

    Note the exact spelling and two leading underscores. If these are not correctly set, you will get messages from PROFILE.DLL warning you that these settings cannot be found.

    In this example, if your compiler is on your D drive, these variables would be:

    d:\...\samples\sdk\winnt\service\simple.pbi
    d:\...\samples\sdk\winnt\service\simple.pbo
    
  3. Copy the profiler DLL, PROFILE.DLL, from the Program Files\Microsoft Visual Studio\VC98\bin subdirectory to either the directory where the service .EXE resides or to one of the directories listed in the PATH environment variable.

  4. Build the sample, SIMPLE.EXE. Instruct the linker to create a .MAP file.

  5. Run PREP to create SIMPLE._XE, which has been modified for profiling:

    prep /om /ft /sf _worker_thread simple.exe
    

    This command also sets up the code to follow the call stack from the worker_thread() routine. By default, the profiler profiles calls from the main thread, so servicing requests from a secondary thread without specifying the /sf option will produce incomplete results. In the sample, this second thread is created by calling CreateThread( ) to service the requests. If the main thread was servicing the requests, you wouldn't need to use the /sf option.

  6. Copy SIMPLE._XE to SIMPLE.EXE. This overwrites the original executable file with the modified version, which has the profile hooks added to the code.

  7. Start the service by using the Services program in the Control Panel, and run the client application. Stop the service using the Control Panel. You can get the timing information by executing the following commands from the command prompt:

    prep /m simple
    plist simple