diff --git a/README.md b/README.md index e966a88b65..5d7955e5df 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,20 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder +### Comparing performance runs + +Run the same workload twice with `XCL_ACTIVITY=1` (also enabled by `scripts/smoke.ps1`). +Keep each resulting `xcl.log`, then compare them: + +```powershell +.\scripts\compare-perf.ps1 -Baseline .\base.log -Candidate .\candidate.log +``` + +The table pairs two-second activity samples from startup up to the shorter run. It shows each +sample's elapsed time, presentation count and DirectStorage request count. Peak process commit +uses the available memory samples in that common span. The first displayed frame time is read +from each whole log and may include a black frame. + ## Tests ```powershell diff --git a/scripts/compare-perf.ps1 b/scripts/compare-perf.ps1 new file mode 100644 index 0000000000..066d0167ca --- /dev/null +++ b/scripts/compare-perf.ps1 @@ -0,0 +1,70 @@ +param( + [Parameter(Mandatory = $true)][string]$Baseline, + [Parameter(Mandatory = $true)][string]$Candidate +) + +$ErrorActionPreference = 'Stop' + +function Read-PerformanceLog($Path, $Label) { + $firstFrame = $null + $samples = [System.Collections.Generic.List[object]]::new() + # XCL logs one activity line per interval, followed by its memory sample. + $timestamp = '^\[\s*(?[0-9]+\.[0-9]+)\]' + $file = Convert-Path -LiteralPath $Path + $share = [IO.FileShare]::ReadWrite -bor [IO.FileShare]::Delete + $stream = [IO.File]::Open($file, [IO.FileMode]::Open, [IO.FileAccess]::Read, $share) + $reader = [IO.StreamReader]::new($stream, [Text.Encoding]::UTF8, $true) + try { + while ($null -ne ($line = $reader.ReadLine())) { + if ($line -match ($timestamp + '.*?present: first game frame shown \(')) { + if ($null -eq $firstFrame) { $firstFrame = $Matches.seconds } + } elseif ($line -match ($timestamp + '.*?activity \(2 s\): (?\d+) presents,.*?; DirectStorage (?\d+) requests,')) { + $samples.Add([pscustomobject]@{ + End = $Matches.seconds + Presents = [long]$Matches.presents + Requests = [long]$Matches.requests + Commit = $null + }) + } elseif ($samples.Count -gt 0 -and $line -match 'memory: (?\d+) MB committed by the process;') { + $samples[$samples.Count - 1].Commit = [long]$Matches.commit + } + } + } finally { + $reader.Dispose() + } + if ($samples.Count -eq 0) { + throw "$Label log contains no two-second activity samples. Run XCL with XCL_ACTIVITY=1." + } + [pscustomobject]@{ FirstFrame = $firstFrame; Samples = $samples } +} + +$base = Read-PerformanceLog $Baseline 'Baseline' +$next = Read-PerformanceLog $Candidate 'Candidate' +$count = [Math]::Min($base.Samples.Count, $next.Samples.Count) +$basePeak = $null +$nextPeak = $null +$rows = for ($index = 0; $index -lt $count; $index++) { + $before = $base.Samples[$index] + $after = $next.Samples[$index] + if ($null -ne $before.Commit -and ($null -eq $basePeak -or $before.Commit -gt $basePeak)) { $basePeak = $before.Commit } + if ($null -ne $after.Commit -and ($null -eq $nextPeak -or $after.Commit -gt $nextPeak)) { $nextPeak = $after.Commit } + [pscustomobject]@{ + 'Sample' = $index + 1 + 'Base s' = $before.End + 'New s' = $after.End + 'Base presents' = $before.Presents + 'New presents' = $after.Presents + 'Base DS' = $before.Requests + 'New DS' = $after.Requests + } +} + +"Compared $count two-second samples from startup (baseline $($base.Samples.Count), candidate $($next.Samples.Count))." +$baseFrame = if ($null -eq $base.FirstFrame) { 'n/a' } else { "$($base.FirstFrame) s" } +$nextFrame = if ($null -eq $next.FirstFrame) { 'n/a' } else { "$($next.FirstFrame) s" } +if ($null -eq $basePeak) { $basePeak = 'n/a' } +if ($null -eq $nextPeak) { $nextPeak = 'n/a' } +"First frame shown: baseline $baseFrame, candidate $nextFrame" +"Peak sampled process commit (MB): baseline $basePeak, candidate $nextPeak" +"DS columns count DirectStorage requests." +$rows | Format-Table -AutoSize diff --git a/scripts/compare-perf.tests.ps1 b/scripts/compare-perf.tests.ps1 new file mode 100644 index 0000000000..d32a74cf61 --- /dev/null +++ b/scripts/compare-perf.tests.ps1 @@ -0,0 +1,49 @@ +$ErrorActionPreference = 'Stop' +$script = Join-Path $PSScriptRoot 'compare-perf.ps1' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-compare-perf-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$base = Join-Path $fixture 'base[1].log' +$candidate = Join-Path $fixture 'candidate.log' +try { + [IO.File]::WriteAllLines($base, @( + 'game: private-path' + '[ 1.123][5][INFO ] present: first game frame shown (1280x720)' + '[ 2.002][5][INFO ] activity (2 s): 12 presents, 3 submits; DirectStorage 5 requests, 2 MB, 0 failed' + '[ 2.003][5][INFO ] memory: 100 MB committed by the process; video memory 80 MB local' + '[ 4.004][5][INFO ] activity (2 s): 9 presents, 3 submits; DirectStorage 3 requests, 2 MB, 0 failed' + '[ 4.005][5][INFO ] memory: 999 MB committed by the process; video memory 80 MB local' + )) + [IO.File]::WriteAllLines($candidate, @( + '[ 2.001][5][INFO ] activity (2 s): 14 presents, 3 submits; DirectStorage 8 requests, 2 MB, 0 failed' + )) + $output = & $script -Baseline $base -Candidate $candidate | Out-String -Width 240 + if ($output -notmatch 'Compared 1 two-second samples.*baseline 2, candidate 1' -or + $output -notmatch 'First frame shown: baseline 1\.123 s, candidate n/a' -or + $output -notmatch 'Peak sampled process commit \(MB\): baseline 100, candidate n/a' -or + $output -notmatch '(?m)^\s*1\s+2\.002\s+2\.001\s+12\s+14\s+5\s+8\s*$' -or + $output -match 'private-path|999') { + throw "Unexpected comparison output: $output" + } + + [IO.File]::WriteAllText($candidate, 'No activity samples') + try { + & $script -Baseline $base -Candidate $candidate + throw 'Expected an error for a log without activity samples.' + } catch { + if ($_.Exception.Message -notmatch 'Candidate log contains no two-second activity samples') { throw } + } + # A writer may still own the file. Read an unterminated UTF-16 sample through a relative path. + $sample = '[ 2.500][5][INFO ] activity (2 s): 6 presents, 1 submits; DirectStorage 4 requests, 0 MB, 0 failed' + [IO.File]::WriteAllText($base, $sample, [Text.Encoding]::Unicode) + $writer = [IO.File]::Open($base, [IO.FileMode]::Open, [IO.FileAccess]::Write, [IO.FileShare]::ReadWrite) + try { + Push-Location -LiteralPath $fixture + try { $output = & $script -Baseline 'base[1].log' -Candidate 'base[1].log' | Out-String -Width 240 } + finally { Pop-Location } + } finally { $writer.Dispose() } + if ($output -notmatch '(?m)^\s*1\s+2\.500\s+2\.500\s+6\s+6\s+4\s+4\s*$') { throw $output } + 'compare-perf: all three fixture checks passed' +} finally { + Remove-Item -LiteralPath $base, $candidate -ErrorAction SilentlyContinue + Remove-Item -LiteralPath $fixture +}