Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,20 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder

</details>

### 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
Expand Down
70 changes: 70 additions & 0 deletions scripts/compare-perf.ps1
Original file line number Diff line number Diff line change
@@ -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*(?<seconds>[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\): (?<presents>\d+) presents,.*?; DirectStorage (?<requests>\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: (?<commit>\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
49 changes: 49 additions & 0 deletions scripts/compare-perf.tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
Loading