microsoft/TypeAgent
Publicmirrored fromhttps://github.com/microsoft/TypeAgentAvailable
dotnet/agentLauncher/src/Show-Timing.ps1
48lines · modecode
| 1 | $ErrorActionPreference = "Stop" |
| 2 | |
| 3 | $logPath = Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'AgentLauncher\agent.log' |
| 4 | |
| 5 | if (-not (Test-Path $logPath)) { |
| 6 | Write-Host "Log file not found at: $logPath" -ForegroundColor Red |
| 7 | exit 1 |
| 8 | } |
| 9 | |
| 10 | Write-Host "`nTiming Analysis - Latest Activation" -ForegroundColor Cyan |
| 11 | Write-Host "====================================`n" -ForegroundColor Cyan |
| 12 | |
| 13 | # Get timing lines from the latest activation |
| 14 | $timingLines = Get-Content $logPath | Where-Object { $_ -match 'TIMING' } | Select-Object -Last 20 |
| 15 | |
| 16 | if ($timingLines.Count -eq 0) { |
| 17 | Write-Host "No timing data found in log" -ForegroundColor Yellow |
| 18 | exit 0 |
| 19 | } |
| 20 | |
| 21 | Write-Host "Detailed Timing Breakdown:" -ForegroundColor Green |
| 22 | Write-Host "" |
| 23 | |
| 24 | $previousMs = 0 |
| 25 | foreach ($line in $timingLines) { |
| 26 | if ($line -match '\[TIMING \[([^\]]+)\]\] \+(\d+)ms - (.+)') { |
| 27 | $marker = $matches[1] |
| 28 | $totalMs = [int]$matches[2] |
| 29 | $description = $matches[3] |
| 30 | $delta = $totalMs - $previousMs |
| 31 | |
| 32 | $color = "White" |
| 33 | if ($delta -gt 1000) { $color = "Red" } |
| 34 | elseif ($delta -gt 500) { $color = "Yellow" } |
| 35 | elseif ($delta -gt 100) { $color = "Cyan" } |
| 36 | |
| 37 | Write-Host (" {0,-30} {1,6}ms (Δ{2,6}ms) {3}" -f $marker, $totalMs, $delta, $description) -ForegroundColor $color |
| 38 | $previousMs = $totalMs |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | Write-Host "`n" -ForegroundColor Cyan |
| 43 | Write-Host "Total Time: ${previousMs}ms" -ForegroundColor Green |
| 44 | Write-Host "`nColor Legend:" -ForegroundColor Gray |
| 45 | Write-Host " Red = >1000ms (1+ seconds)" -ForegroundColor Red |
| 46 | Write-Host " Yellow = >500ms" -ForegroundColor Yellow |
| 47 | Write-Host " Cyan = >100ms" -ForegroundColor Cyan |
| 48 | Write-Host " White = <100ms" -ForegroundColor White |
| 49 | |