Profiling Windows Services

Intel® VTuneTM Amplifier XE has a limited ability to profile Windows* services. However it is possible using a workaround that is described in this article.

There is no problem if Hardware Event-Based Sampling analysis is used (e.g. Lightweight Hotspots). You just need to run the analyzed service from the same user account that is used to run VTune Amplifier XE. Then you can simply attach the profiler to the service process.

When user-mode analysis is used, it comes a little bit tricky. The problem here is that VTune Amplifier XE adds binary instrumentation to analyzed processes. Windows* tries to limit such insertions for security reasons. Recent versions of Windows (starting with Vista*) have a separate session for services - session 0. User applications run in other sessions where users are logged in: session 1 to N. You can read more about session 0 isolation.

Since VTune Amplifier XE runs in a normal logon session and the service of interest runs in session 0, there appears a barrier for binary instrumentation and profiling.

This barrier can be worked around by using PsExec utility. It can be downloaded here. Download and extract the archive, then put psexec.exe into your current working directory, or configure the PATH environment variable to include it.

Steps to profile Windows service in CLI mode
1. Configure analyzed service to run with permissions of current user
2. Run <amplifier_xe_install_dir>/amplxe-vars.bat to configure VTune Amplifier XE environment
3. Get PID of analyzed service
4. Run the following command to attach to the service and start collection (for Hotspots analysis):

> psexec -i 0 amplxe-cl.exe -c=hotspots -r \path\for\your\result_dir --target-pid=PID

5. Run your workload
6. Detach VTune Amplifier XE from the service:

> psexec -i 0 amplxe-cl.exe -command detach -r \path\for\your\result_dir

7. Open the collected results in VTune Amplifier XE GUI

Steps to profile Windows service in GUI mode
1. Configure analyzed service to run with permissions of current user
2. Run <amplifier_xe_install_dir>/amplxe-vars.bat to configure VTune Amplifier XE environment
3. Get PID of analyzed service
4. Start the Interactive Services service:

> net start UI0Detect

5. Start VTune Amplifier XE GUI (from command line):

> psexec -i 0 amplxe-gui.exe

6. You will get a blinking task bar icon. Click on that icon and an interactive Services Detection dialog box will pop up. Choose "View the message", that will make Windows change to session 0, which normally does not have any UI elements. But in this session 0 you should see the VTune Amplifier XE GUI, and another dialog box that you can use to get back to your normal logon session.

7. Attach to the services process and use the VTune Amplifier XE GUI as you are used to.

8. After you are done profiling, you can analyze the results in that session. Or close the VTune Amplifier XE GUI and click "Return now" in the dialog box. Then you can reopen the VTune Amplifier XE results in the normal logon session.

9. Stop the Interactive Services service:

> net stop UI0Detect

Some other hints to profiling in session 0
• You can always go back and forth between session 0 and your normal logon session by selecting the "View the message" and "Return now" buttons in the Interactive services dialog boxes.

• Note that other users on the same machine might see the Interactive Services Detection window as well. Make sure they know about this, so they leave the dialog box alone.

• You can run VTune Amplifier XE as a different user than the service process. For this use "-u" parameter of psexec to specify the user under which the service is running. You will be prompted to type the password for the account:

> psexec -u mydomain\myaccount -h -i 0 amplxe-gui.exe

 
*Other names and brands may be claimed as the property of others.

For more complete information about compiler optimizations, see our Optimization Notice.