@@ -107,7 +107,7 @@ switch($Command.ToLowerInvariant()){
107107 New-Item - ItemType Directory - Force - Path $outDir | Out-Null
108108 $fileBase = " trace_${procId} _$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) "
109109 $traceFile = Join-Path $outDir " $fileBase .nettrace"
110- $speedFile = Join-Path $outDir " $fileBase .speedscope.json "
110+ $speedFile = Join-Path $outDir " $fileBase "
111111 Write-Host " Collecting trace for PID $procId ..." - ForegroundColor Cyan
112112 & dotnet- trace collect -- process- id $procId -- providers Microsoft- DotNETCore- SampleProfiler:1 -- duration 00 :00 :10 - o $traceFile
113113 if ($LASTEXITCODE -ne 0 ){
@@ -122,13 +122,17 @@ switch($Command.ToLowerInvariant()){
122122 Write-Host " Speedscope file: $speedFile " - ForegroundColor Green
123123 # Auto-open speedscope view
124124 try {
125+ $speedFile = $speedFile + ' .speedscope.json'
126+ $resolvedSpeed = (Resolve-Path $speedFile ).Path
127+ if (-not (Test-Path $resolvedSpeed )) { throw " Speedscope file not found: $resolvedSpeed " }
125128 if (Get-Command npx - ErrorAction SilentlyContinue){
126- Write-Host ' Opening speedscope (npx)...' - ForegroundColor Cyan
127- & npx speedscope $speedFile
129+ Write-Host " Opening speedscope (npx) -> $resolvedSpeed " - ForegroundColor Cyan
130+ & npx speedscope " $resolvedSpeed "
131+ if ($LASTEXITCODE -ne 0 ){ Write-Host ' npx speedscope returned non-zero; fallback to browser.' - ForegroundColor Yellow; Start-Process ' https://www.speedscope.app' ; Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent) }
128132 } else {
129133 Write-Host ' npx not available; opening speedscope.app and folder.' - ForegroundColor Yellow
130134 Start-Process ' https://www.speedscope.app'
131- Start-Process explorer.exe (Split-Path $speedFile - Parent)
135+ Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent)
132136 }
133137 } catch { Write-Host " Speedscope auto-open failed: $ ( $_.Exception.Message ) " - ForegroundColor Yellow }
134138 }
@@ -150,7 +154,7 @@ switch($Command.ToLowerInvariant()){
150154 New-Item - ItemType Directory - Force - Path $outDir | Out-Null
151155 $fileBase = " cpu_${procId} _$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) "
152156 $traceFile = Join-Path $outDir " $fileBase .nettrace"
153- $speedFile = Join-Path $outDir " $fileBase .speedscope.json "
157+ $speedFile = Join-Path $outDir " $fileBase "
154158 Write-Host " Collecting CPU trace (SampleProfiler, $duration ) for PID $procId ..." - ForegroundColor Cyan
155159 & dotnet- trace collect -- process- id $procId -- providers Microsoft- DotNETCore- SampleProfiler:1 -- duration $duration - o $traceFile
156160 if ($LASTEXITCODE -ne 0 ){ throw ' CPU trace collection failed' }
@@ -159,14 +163,19 @@ switch($Command.ToLowerInvariant()){
159163 if ($LASTEXITCODE -ne 0 ){ throw ' CPU trace conversion failed' }
160164 Write-Host " CPU trace complete: $traceFile " - ForegroundColor Green
161165 Write-Host " Speedscope file: $speedFile " - ForegroundColor Green
166+ # Auto-open speedscope view
162167 try {
168+ $speedFile = $speedFile + ' .speedscope.json'
169+ $resolvedSpeed = (Resolve-Path $speedFile ).Path
170+ if (-not (Test-Path $resolvedSpeed )) { throw " Speedscope file not found: $resolvedSpeed " }
163171 if (Get-Command npx - ErrorAction SilentlyContinue){
164- Write-Host ' Opening speedscope (npx)...' - ForegroundColor Cyan
165- & npx speedscope $speedFile
172+ Write-Host " Opening speedscope (npx) -> $resolvedSpeed " - ForegroundColor Cyan
173+ & npx speedscope " $resolvedSpeed "
174+ if ($LASTEXITCODE -ne 0 ){ Write-Host ' npx speedscope returned non-zero; fallback to browser.' - ForegroundColor Yellow; Start-Process ' https://www.speedscope.app' ; Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent) }
166175 } else {
167176 Write-Host ' npx not available; opening speedscope.app and folder.' - ForegroundColor Yellow
168177 Start-Process ' https://www.speedscope.app'
169- Start-Process explorer.exe (Split-Path $speedFile - Parent)
178+ Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent)
170179 }
171180 } catch { Write-Host " Speedscope auto-open failed: $ ( $_.Exception.Message ) " - ForegroundColor Yellow }
172181 }
@@ -188,7 +197,7 @@ switch($Command.ToLowerInvariant()){
188197 New-Item - ItemType Directory - Force - Path $outDir | Out-Null
189198 $fileBase = " gc_${procId} _$ ( Get-Date - Format ' yyyyMMdd_HHmmss' ) "
190199 $traceFile = Join-Path $outDir " $fileBase .nettrace"
191- $speedFile = Join-Path $outDir " $fileBase .speedscope.json "
200+ $speedFile = Join-Path $outDir " $fileBase "
192201 Write-Host " Collecting GC-focused trace (SampleProfiler + System.Runtime, $duration ) for PID $procId ..." - ForegroundColor Cyan
193202 & dotnet- trace collect -- process- id $procId -- providers Microsoft- DotNETCore- SampleProfiler:1 , System.Runtime:4 -- duration $duration - o $traceFile
194203 if ($LASTEXITCODE -ne 0 ){ throw ' GC trace collection failed' }
@@ -197,14 +206,19 @@ switch($Command.ToLowerInvariant()){
197206 if ($LASTEXITCODE -ne 0 ){ throw ' GC trace conversion failed' }
198207 Write-Host " GC trace complete: $traceFile " - ForegroundColor Green
199208 Write-Host " Speedscope file: $speedFile " - ForegroundColor Green
209+ # Auto-open speedscope view
200210 try {
211+ $speedFile = $speedFile + ' .speedscope.json'
212+ $resolvedSpeed = (Resolve-Path $speedFile ).Path
213+ if (-not (Test-Path $resolvedSpeed )) { throw " Speedscope file not found: $resolvedSpeed " }
201214 if (Get-Command npx - ErrorAction SilentlyContinue){
202- Write-Host ' Opening speedscope (npx)...' - ForegroundColor Cyan
203- & npx speedscope $speedFile
215+ Write-Host " Opening speedscope (npx) -> $resolvedSpeed " - ForegroundColor Cyan
216+ & npx speedscope " $resolvedSpeed "
217+ if ($LASTEXITCODE -ne 0 ){ Write-Host ' npx speedscope returned non-zero; fallback to browser.' - ForegroundColor Yellow; Start-Process ' https://www.speedscope.app' ; Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent) }
204218 } else {
205219 Write-Host ' npx not available; opening speedscope.app and folder.' - ForegroundColor Yellow
206220 Start-Process ' https://www.speedscope.app'
207- Start-Process explorer.exe (Split-Path $speedFile - Parent)
221+ Start-Process explorer.exe (Split-Path $resolvedSpeed - Parent)
208222 }
209223 } catch { Write-Host " Speedscope auto-open failed: $ ( $_.Exception.Message ) " - ForegroundColor Yellow }
210224 }
0 commit comments