How to analyze multiple userdumps and generate one report per userdump using Debugdiag 1.1

In many situations, you may find it useful to analyze multiple userdumps at once but generate an analysis report for each userdump analyzed.

The Debugdiag UI can still do that, but there is no option now (1.1) to make it generate one analysis report per userdump. If -let's say- you would like to analyze 10 userdumps, then the generated analysis report would be just too big for IE to open and if it does navigating through the report would be painful.

The below VBScript code, allows you to specify a folder where the userdumps are located and run one type of analysis at a time against all the userdumps contained in the folder.

 

    1: 'Purpose
    2: '=======
    3: ' Analyze memory dumps using debugdiag's debugger host "dbghost.exe" without 
    4: 'requiring the user interface
    5:  
    6:  
    7:  
    8: 'Requirements for the script
    9: ' Save the script to the \Scripts folder where debugdiag is installed i.e 
   10: 'C:\Program Files\DebugDiag\Scripts
   11: ' Use the command prompt and run the command "cscript.exe AnalyzeAllDumps.vbs 
   12: '<Analysis Type>"
   13: ' <Analysis Type> could be Crash, Hang or Memory
   14:  
   15: ' For each run, the script creates a log file under C:\Program 
   16: 'Files\DebugDiag\Reports\Auto-RTW-1-1 containing run 
   17: 'information 
   18: ' The analysis reports are created under C:\Program 
   19: 'Files\DebugDiag\Reports\Auto-RTW-1-1\. For each memory dump 
   20: 'analyzed, there will be a report analysis file generated 
   21:  
   22:  
   23:  
   24:  
   25: 'Change to True if you want a script failure to trigger the JIT debugger
   26: Const DEBUG_ON_ERROR = FALSE 
   27: Const SYMBOL_PATH = "srv*c:\symcache*http://msdl.microsoft.com/download/symbols"
   28: Const SCRIPTS_VERSION = "Auto-RTW-1-1"
   29: Const DUMP_LOCATION = \\serverName\folderName
   30:  
   31: Const REPORT_LOCATION = "C:\Program Files\DebugDiag"
   32:  
   33: 'Location where the analysis reports are to be placed
   34: ANALYSIS_REPORT_PATH = REPORT_LOCATION & "\Reports\" & SCRIPTS_VERSION & "\" 
   35: 'Location where the run log file is to be created
   36: RUN_REPORT_PATH = REPORT_LOCATION & "\Logs\" & SCRIPTS_VERSION & "\" 
   37: Set PROGRESS_SINK = Nothing
   38:  
   39:  
   40: Set g_DumpFileList = CreateObject("Scripting.Dictionary")
   41:  
   42: Set WshArgs = WScript.Arguments
   43:  
   44: If WshArgs.Length = 1 then
   45: Select Case UCase(WshArgs(0))
   46: Case "HANG", "CRASH", "MEMORY"
   47: Case Else
   48: PrintHelp "INVALID ARGUMENT"
   49: WriteLine("Invalid argument passed. Run cancelled")
   50: WScript.Quit
   51: End Select
   52: Set oFSO = CreateObject("Scripting.FileSystemObject")
   53: startDate = Now()
   54: startDate = Replace(startDate, " ", "_")
   55: startDate = Replace(startDate, ":", "_")
   56: startDate = Replace(startDate, "/", "_")
   57:  
   58:  
   59: if ReportFolderStatus (RUN_REPORT_PATH)= false Then 
   60: oFSO.CreateFolder(RUN_REPORT_PATH)
   61: End if
   62:  
   63: if ReportFolderStatus (ANALYSIS_REPORT_PATH)= false Then 
   64: oFSO.CreateFolder(ANALYSIS_REPORT_PATH) 
   65: End if
   66:  
   67:  
   68: Set logFile = oFSO.CreateTextFile(RUN_REPORT_PATH & UCase(WshArgs(0)) & 
   69: "_Script_Run_" & startDate & ".log")
   70:  
   71: g_DumpFileList.RemoveAll()
   72:  
   73: ' Recurse through the memory dumps location and add all dump files to the analysis 
   74: 'list
   75: If Instr(UCase(WshArgs(0)), "CRASH") > 0 Then
   76: AddFilesToAL oFSO.GetFolder(DUMP_LOCATION)
   77: SCRIPT_TO_RUN = "CrashHangAnalysis.asp"
   78: End If
   79:  
   80: If Instr(UCase(WshArgs(0)), "HANG") > 0 Then
   81: AddFilesToAL oFSO.GetFolder(DUMP_LOCATION)
   82: SCRIPT_TO_RUN = "CrashHangAnalysis.asp"
   83: End If
   84:  
   85: If UCase(WshArgs(0)) = "MEMORY" Then
   86: AddFilesToAL oFSO.GetFolder(DUMP_LOCATION)
   87: SCRIPT_TO_RUN = "MemoryAnalysis.asp"
   88: End If
   89: WScript.Echo ""
   90: WScript.Echo "Starting run using analysis script " & SCRIPT_TO_RUN
   91:  
   92: WriteLine("Beginning " & UCase(WshArgs(0)) & " analysis run using " & 
   93: g_DumpFileList.Count & " dump files. Run 
   94: started at " & Now())
   95: WriteLine("")
   96:  
   97: For Each oFile in g_DumpFileList 
   98: bTest = False
   99: Progress = 0
  100: Set Controller = CreateObject("DbgHost.DbgControl")
  101: Set Analyzer = Controller.Analyzer
  102:  
  103: Analyzer.DataFiles.Add oFile
  104:  
  105: ' Set the analysis script we're gonna run these dump files against
  106: Analyzer.AddScriptToRunList SCRIPT_TO_RUN
  107:  
  108: WriteLine("Now analyzing dump file " & oFile)
  109: WScript.Echo ""
  110: WScript.Echo "Now analyzing dump file " & oFile
  111: tStart = Timer
  112: Analyzer.RunScripts PROGRESS_SINK, SYMBOL_PATH, ANALYSIS_REPORT_PATH, 
  113: DEBUG_ON_ERROR
  114:  
  115: 'Wait until the current analysis run is complete before starting the next 
  116: one
  117: Do Until Analyzer.ReportReady
  118: WScript.Sleep 500
  119: Loop
  120:  
  121: WriteLine("Analysis complete for " & oFile)
  122:  
  123: WScript.Echo ""
  124: WScript.Echo "Analysis complete for " & oFile
  125:  
  126: WScript.Echo ""
  127: WScript.Echo "Analysis Report generated at: " & ANALYSIS_REPORT_PATH & 
  128: "\" & Analyzer.ReportFileName
  129:  
  130: Set Controller = Nothing 
  131: Set Analyzer = Nothing
  132: Next
  133:  
  134: WScript.Echo ""
  135: WScript.Echo "Analysis batch job completed."
  136:  
  137: WriteLine("")
  138: WriteLine("Run completed at " & Now())
  139:  
  140: logFile.Close
  141: Else
  142: PrintHelp "Use the below syntax to perform Crash, Hang or Leak analysis against 
  143: memory dumps"
  144: End If
  145:  
  146:  
  147: ' This sub adds all files with .dmp extension to the list of files to analyze
  148: Sub AddFilesToAL(oFolder)
  149: Dim oSubFolder, oFile
  150:  
  151: For Each oFile in oFolder.Files
  152: If LCase(Right(oFile.Name, 4)) = ".dmp" Then
  153: g_DumpFileList.Add oFile, oFile.Name
  154: End If
  155: Next
  156:  
  157: ' Don't forget subfolders... recursivly
  158: For Each oSubFolder in oFolder.SubFolders
  159: AddFilesToAL oSubFolder
  160: Next
  161: End Sub
  162:  
  163: ' Help Usage
  164: Sub PrintHelp(ByVal sFirstLine)
  165: WScript.Echo ""
  166: WScript.Echo sFirstLine
  167: WScript.Echo ""
  168: WScript.Echo "Usage:"
  169: WScript.Echo WScript.ScriptName &" <Memory | Crash | Hang>"
  170: WScript.Echo "Example:"
  171: WScript.Echo WScript.ScriptName &" Crash"
  172: End Sub
  173:  
  174: ' Write to the log file
  175: Sub WriteLine(s)
  176: logFile.WriteLine Now & " -- " & s
  177: End Sub
  178:  
  179: ' If a folder exists
  180: Function ReportFolderStatus(fldr)
  181: Dim fso, bMsg
  182: Set fso = CreateObject("Scripting.FileSystemObject")
  183: If (fso.FolderExists(fldr)) Then
  184: bMsg = TRUE
  185: Else
  186: bMsg = FALSE
  187: End If
  188: ReportFolderStatus = bMsg
  189: End Function

To run the script, copy the code into a VBS file "AnalyzeAllDumps.vbs" and place it into the scripts folder in the Debugdiag installation folder (ie: C:\program files\Debugdiag>.

In the command prompt, run the below command:

    1: C:\Program Files\DebugDiag\Scripts>cscript.exe AnalyzeAllDumps.vbs <Memory | Crash | Hang>

 

Technorati Tags: Debugdiag,analysis,ie,mhtml,report