The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Investigate Crashes & Memory Leaks in your Windows Services with Microsoft’s Debug Diagnostic Tool

Microsoft Debug Diagnostic Tool

Crashes and memory leaks are particularly offensive when the occur in windows services – applications designed to run unattended, 24/7 in the background to perform important tasks. Our AlwaysUp and Service Protector utilities go a long way to diminishing the effect of these insidious failures, but using them is no substitute for finding and fixing a problem at its root.

Developers looking to diagnose failures in their windows services should consider using Microsoft’s Debug Diagnostic Tool. This free desktop application, nicknamed DebugDiag, will monitor your windows service process and create a “dump” describing the state of the application when it crashed (or started using too much memory). You can use this information to narrow down the problem in your own code, or pass it on to the folks who developed the failing service for their expert analysis.

Using the Debug Diagnostic Tool on your Windows Service

  1. Download the Debug Diagnostic Tool from microsoft.com.

  2. Install it. Setup should be quite straightforward, with the usual prompts for a folder, etc.

  3. From Windows Explorer, navigate to the folder where DebugDiag was installed (C:\Program Files\DebugDiag by default). Start DebugDiag.Collection.exe – the application that monitors and collects information from a running process or service.


    Start DebugDiag.Collection.exe

  4. The Debug Diagnostic Tool window should come up and you will be launched immediately into setting up a new “rule” describing what to watch for. From here, you can specify to monitor for crashes, leaks, and even performance-related issues. We’ll select Crash for this tutorial and click Next to move on.


    DebugDiag: Select Crash Option

  5. Next, select the A Specific NT service option:


    DebugDiag: Select Windows Service Option

  6. Select the service you wish to debug from the list. We chose “AA MyService”, a windows service we developed to test our Service Protector application. Click Next.


    DebugDiag: Select Windows Service

  7. Almost there! Leave the Advanced Configuration settings at their default values and click Next to continue:


    DebugDiag: Windows Service Advanced Configuration

  8. You don’t have to make any changes on the Select Dump Location screen either – just make a note of where the dump file will be saved.


    DebugDiag: Windows Service Dump Location

  9. And finally, let’s activate the rule now and click Finish:


    DebugDiag: Activate Now

    After a few seconds, the tool will be monitoring your windows service for crashes:


    DebugDiag: Windows Service Rule Created

Analyzing a Windows Service Crash

When the service crashes, DebugDiag will record a dump file and increment the Userdump count column. Here we can see that 1 crash has occurred and been captured (with the full path to the dump file noted on the right):


DebugDiag: Windows Service Crashed

To dig into the dump file:

  1. Start DebugDiag.Analysis.exe from Windows Explorer:


    Start DebugDiag.Analysis.exe

    The DebugDiag Analysis window will open momentarily:


    DebugDiag Analysis Started

  2. To configure analysis:

    1. Check the CrashHangAnalysis box near to the top.
    2. Click the Add Data Files button, navigate to the location of the dump file (it is mentioned in the Diagnostic tool we set up previously) and select it. A new entry should show up in the lower pane.


    Configure Analysis

  3. And click the Start Analysis button to get going! After a period of “thinking”, the application will open its report in your browser:


    Analysis Summary Report

  4. Scan the report for any smoking guns. Thread call stacks may be particularly useful. For example, this stack trace tells us that our service crashed while handling a button press. (This is not surprising though – that is what we did to force the crash in our testing!)


    Windows Service Call Stack

    Hopefully you will find a telltale sign to help you identify and fix your problem.

Also Find Memory Leaks in your Windows Service

If your windows service is consuming too much memory instead of crashing, configure the collector to watch for memory leaks:


Find Windows Service Memory Leaks

The final report will detail all outstanding memory allocations.

 

Good hunting!

Posted in Windows Services | Tagged , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *