FinishDumpCollectionForHangingBuilds.ps1 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. param(
  2. [Parameter(Mandatory = $true)]
  3. [ValidateNotNullOrEmpty()]
  4. [string]
  5. $ProcDumpOutputPath
  6. )
  7. Write-Output "Finishing dump collection for hanging builds.";
  8. $repoRoot = Resolve-Path "$PSScriptRoot\..\..";
  9. $ProcDumpOutputPath = Join-Path $repoRoot $ProcDumpOutputPath;
  10. $sentinelFile = Join-Path $ProcDumpOutputPath "dump-sentinel.txt";
  11. if ((-not (Test-Path $sentinelFile))) {
  12. Write-Output "No sentinel file available in '$sentinelFile'. " +
  13. "StartDumpCollectionForHangingBuilds.ps1 has not been executed, is not correctly configured or failed before creating the sentinel file.";
  14. return;
  15. }
  16. Get-Process "procdump" -ErrorAction SilentlyContinue | ForEach-Object { Write-Output "ProcDump with PID $($_.Id) is still running."; };
  17. $capturedDumps = Get-ChildItem $ProcDumpOutputPath -Filter *.dmp;
  18. $capturedDumps | ForEach-Object { Write-Output "Found captured dump $_"; };
  19. $JobName = (Get-Content $sentinelFile);
  20. if ($JobName.Count -ne 1) {
  21. if ($JobName.Count -eq 0) {
  22. Write-Warning "No job name found. This is likely an error.";
  23. return;
  24. }
  25. else {
  26. Write-Output "Multiple job names found '$JobName'.";
  27. return;
  28. }
  29. }
  30. $dumpCollectionJob = Get-Job -Name $JobName -ErrorAction SilentlyContinue;
  31. $registeredJob = Get-ScheduledJob -Name $JobName -ErrorAction SilentlyContinue;
  32. if ($null -eq $dumpCollectionJob) {
  33. Write-Output "No job found for '$JobName'. It either didn't run or there is an issue with the job definition.";
  34. if ($null -eq $registeredJob) {
  35. Write-Warning "Couldn't find a scheduled job '$JobName'.";
  36. }
  37. return;
  38. }
  39. Write-Output "Listing existing jobs";
  40. Get-Job -Name CaptureDumps*
  41. Write-Output "Listing existing scheduled jobs";
  42. Get-ScheduledJob -Name CaptureDumps*
  43. Write-Output "Displaying job output";
  44. Receive-Job $dumpCollectionJob;
  45. Write-Output "Waiting for current job to finish";
  46. Get-Job -ErrorAction SilentlyContinue | Wait-Job;
  47. try {
  48. Write-Output "Removing collection job";
  49. Remove-Job $dumpCollectionJob;
  50. }
  51. catch {
  52. Write-Output "Failed to remove collection job";
  53. }
  54. try {
  55. Write-Output "Unregistering scheduled job";
  56. Unregister-ScheduledJob $registeredJob;
  57. }
  58. catch {
  59. Write-Output "Failed to unregister $JobName";
  60. }