CodeTrack: Profiling a windows service

Back to How To

This can be used to profile any .NET windows service.

For profiling a windows service, it is necessary to run the profiler in elevated mode (you can do this by clicking on the elevation icon in the title bar, or run the profiler as admin). In case of windows services it is usually necessary to start the profiler with the same account as your service (using shift + right click in windows explorer and selecting 'Run as different user'). Alternatively you can also let your service run with the account of your profiler instead.

  1. Select the collect tab (on the left of the application)
  2. Select ‘Service’ and click the arrow on the right to go to the next step.

  3. Now you can select the service you want to profile.
    The bittness and DotNet version should be selected automatically. Should this be incorrect, you can still change this manually.
    Now click the arrow on the right to go to the next step.

  4. Now it's time to decide upon your level of detail. Important to remember, is that the more detail you require, the higher the impact profiling will have on your performance. If you just started investigating a problem, it might be a good idea to use the sampling option. Since this will be the most performant profiling mode. From this information you can then start another session with much more detail, profiling only the code that causes the performance issue.
    For more information about the different profiling settings, read Profiling Modes.

    Now we are ready for the last step, click on the right arrow to continue.
  5. In this last section you need to select the destination of the profiling data. (Make sure you select a location with enough space if you profile with lots of detail).
    If you want to als profile a child process (started by our own process), enable this before starting to profile.
    If you need to profile on a very slow machine,one with little RAM, or a production server, you can disable the processing of the data. This allows you to do the number crunching offline on another machine.

    If you want to start profiling immediately, make sure you click the record button, otherwise click the pause button and hit record from the moment you want to start capturing data.
    Now you are ready to start profiling. If you click the play button, your service will be started (or restarted if it was already running).
    If you press the stop button Codetrack will stop your service (and restart it, if it was running before).