From 53bf014dc3969dcfea1dc7ce8a960f234fd1acd1 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:22:48 -0800 Subject: [PATCH] Updates procdump --- procDump.ps1 | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/procDump.ps1 b/procDump.ps1 index 9ae818572..926d2ba1e 100644 --- a/procDump.ps1 +++ b/procDump.ps1 @@ -53,17 +53,41 @@ Write-Host "Running schema generator" #$process = Start-Process -FilePath "dotnet.exe" -PassThru -ArgumentList "tool run ModernUOSchemaGenerator -- ModernUO.sln" $toolProcess = Run-Process "dotnet.exe" "tool run ModernUOSchemaGenerator -- ModernUO.sln" -Write-Host "Running procdump" -$dumpProcess = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -s 5 -n 5 $($toolProcess.Id) $procDumpFolder" +$dumpProcesses = @() +$startTime = Get-Date +while (-not $toolProcess.HasExited) { + + # break after 1 minute as the tool process will likely never exit + $currentTime = Get-Date + $elapsedTime = $currentTime - $startTime + + if ($elapsedTime.TotalMinutes -ge 1) { + Write-Host "Ending, 1 minute has passed." + break + } + + $commandLines = Get-CimInstance Win32_Process | Select-Object ProcessId, Name, CommandLine + foreach ($commandLine in $commandLines) { + if ($dumpProcesses -contains $commandLine.ProcessId) { + continue + } + + if ($commandLine.CommandLine -like "*ModernUOSchemaGenerator.dll*") { + $dumpProcesses += $commandLine.ProcessId + Write-Host "Attaching to tool process: $($commandLine.ProcessId), Name: $($commandLine.Name), CommandLine: $($commandLine.CommandLine)" + $dmp = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -s 5 -n 5 $($commandLine.ProcessId) $procDumpFolder\Tool_PROCESSNAME_YYMMDD_HHMMSS.dmp" + + } + if ($commandLine.CommandLine -like "*Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll*") { + $dumpProcesses += $commandLine.ProcessId + Write-Host "Attaching to build host process: $($commandLine.ProcessId), Name: $($commandLine.Name), CommandLine: $($commandLine.CommandLine)" + $dmp = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -s 5 -n 5 $($commandLine.ProcessId) $procDumpFolder\BuildHost_PROCESSNAME_YYMMDD_HHMMSS.dmp " + } + } -Write-Host "Waiting for proc dump exit" -while (-not $dumpProcess.HasExited) { Start-Sleep -Seconds 1 } -Write-Host "Killing schema generator" -$toolProcess.Kill() - -# Start-Sleep -Seconds 30 -# $dumpProcess = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -h $($toolProcess.Id) $procDumpFolder" -# $dumpProcess.WaitForExit() +if (-not $toolProcess.HasExited) { + $toolProcess.Kill() +}