Skip to content

Commit bc250e5

Browse files
author
vp
committed
Add interactive duration selection for flame tracing in diagnostics tasks
1 parent f6245a7 commit bc250e5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

.vscode/tasks-diagnostics.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,27 @@ switch($Command.ToLowerInvariant()){
101101
Ensure-Tool 'dotnet-counters' 'dotnet-counters'
102102
Ensure-Tool 'dotnet-trace' 'dotnet-trace'
103103
$script:DotNetOnly = $true
104+
# Duration selection (interactive)
105+
$durationsMap = [ordered]@{ '10 sec'='00:00:10'; '30 sec'='00:00:30'; '1 min'='00:01:00'; '5 min'='00:05:00' }
106+
$duration = $durationsMap['10 sec']
107+
try {
108+
Import-Module PwshSpectreConsole -ErrorAction Stop
109+
$choice = Read-SpectreSelection -Title 'Select flame trace duration' -Choices ($durationsMap.Keys + 'Cancel') -EnableSearch -PageSize 10
110+
if($choice -and $choice -ne 'Cancel'){ $duration = $durationsMap[$choice] }
111+
if($choice -eq 'Cancel'){ Write-Host 'Flame trace cancelled.' -ForegroundColor Yellow; break }
112+
} catch { Write-Host 'Spectre selection unavailable; using default 10 sec.' -ForegroundColor Yellow }
104113
$procId = Select-Pid 'Select process to trace (flame)'
105114
if(-not $procId){ Write-Host 'No PID selected.' -ForegroundColor Yellow; break }
106115
$outDir = Join-Path $PSScriptRoot '..' '.tmp' 'diagnostics'
107116
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
108117
$fileBase = "trace_${procId}_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
109118
$traceFile = Join-Path $outDir "$fileBase.nettrace"
110119
$speedFile = Join-Path $outDir "$fileBase"
111-
Write-Host "Collecting trace for PID $procId ..." -ForegroundColor Cyan
112-
& dotnet-trace collect --process-id $procId --providers Microsoft-DotNETCore-SampleProfiler:1 --duration 00:00:10 -o $traceFile
120+
Write-Host "Collecting flame trace (SampleProfiler, $duration) for PID $procId ..." -ForegroundColor Cyan
121+
& dotnet-trace collect --process-id $procId --providers Microsoft-DotNETCore-SampleProfiler:1 --duration $duration -o $traceFile
113122
if($LASTEXITCODE -ne 0){
114123
Write-Host 'SampleProfiler provider failed, retrying with default trace config (cpu+gc)...' -ForegroundColor Yellow
115-
& dotnet-trace collect --process-id $procId --duration 00:00:10 -o $traceFile
124+
& dotnet-trace collect --process-id $procId --duration $duration -o $traceFile
116125
if($LASTEXITCODE -ne 0){ throw 'Trace collection failed (fallback also failed)' }
117126
}
118127
Write-Host 'Converting to speedscope...' -ForegroundColor Cyan

0 commit comments

Comments
 (0)