private static string AnalyzeDumpFile(AnalysisRequest analysisRequest, string inprogressFile, CancellationToken token) { var blobSasUri = analysisRequest.BlobSasUri; string cpuMonitorPath = MonitoringSessionController.GetCpuMonitoringPath(MonitoringSessionDirectories.Logs); var diagnosticToolsPath = Infrastructure.Settings.GetDiagnosticToolsPath(); string outputPath = Path.Combine(cpuMonitorPath, analysisRequest.SessionId); string inputFile = CacheFileInTempDirectory(analysisRequest); string args = $@"-File ""{diagnosticToolsPath}\DumpAnalyzer.ps1"" ""{inputFile}"" ""{outputPath}"""; var command = @"D:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"; Logger.LogCpuMonitoringVerboseEvent($"Powershell started with args [{args}]", analysisRequest.SessionId); double secondsWaited = 0; var processStartTime = DateTime.UtcNow; var toolProcess = Infrastructure.RunProcess(command, args, analysisRequest.SessionId); while (!toolProcess.HasExited) { // // Keep updating the Expiration time while we are waiting for the DumpAnalyzer to finish // analysisRequest.ExpirationTime = DateTime.UtcNow.AddMinutes(ANALYSIS_HEARTBEAT_EXPIRATION_IN_MINUTES); analysisRequest.ToJsonFile(inprogressFile); Thread.Sleep(10 * 1000); secondsWaited = secondsWaited + 10; if (secondsWaited > 120) { secondsWaited = 0; Logger.LogCpuMonitoringVerboseEvent($"Waiting for Analysis process {command} {args} to finish. Process running for {DateTime.UtcNow.Subtract(processStartTime).TotalSeconds} seconds", analysisRequest.SessionId); } if (token != CancellationToken.None && token.IsCancellationRequested) { Logger.LogCpuMonitoringVerboseEvent($"Kill tool process [{command} {args}] because cancellation is requested", analysisRequest.SessionId); toolProcess.SafeKillProcess(); foreach (var dumpAnalyzer in Process.GetProcesses().Where(x => x.ProcessName.Equals("DumpAnalyzer", StringComparison.OrdinalIgnoreCase))) { Logger.LogCpuMonitoringVerboseEvent($"Going to kill [DumpAnalyzer ({dumpAnalyzer.Id})] because cancellation is requested", analysisRequest.SessionId); dumpAnalyzer.SafeKillProcess(); } token.ThrowIfCancellationRequested(); } } // Delete the file in the temp directory once analysis is done FileSystemHelpers.DeleteFileSafe(inputFile); if (toolProcess.ExitCode != 0) { throw new Exception($"Analysis process exited with error code {toolProcess.ExitCode}"); } var reportNamePattern = Path.GetFileNameWithoutExtension(analysisRequest.LogFileName) + "*.mht"; var reportFilePath = FileSystemHelpers.GetFilesInDirectory(outputPath, reportNamePattern).FirstOrDefault(); Logger.LogCpuMonitoringVerboseEvent($"DumpAnalyzer completed and reportPath is [{reportFilePath}]", analysisRequest.SessionId); return(reportFilePath); }