Skip to content
Draft
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
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,53 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder

</details>

## Reproducible cold and warm runs

On a clean commit, build and run the same title once with fresh XCL caches and once with those
exact caches warm:

```powershell
.\scripts\perf-run.ps1 -Game 'D:\Games\SomeTitle' -OutDir 'D:\xcl-perf\run-1' -Seconds 120
```

The script builds `xcl` in release mode and refuses a dirty worktree or a non-empty output
folder. `-Seconds` counts from the title's start; an XCL-cold run first prepares every shader of
the title, which can take far longer than the default two minutes allowed for startup, so give it
`-StartupTimeoutSeconds` as `smoke.ps1` takes. Both runs use a new temporary `XCL_DATA_ROOT` and `XCL_DXIL_CACHE`; the warm run reuses
the cold run's directories. They are deleted afterwards, and existing user caches are never read,
changed, or deleted. The output folder contains only each run's `xcl.log` and `report.json`, plus
a versioned `manifest.json` with the commit, run order, hardware/toolchain, every `XCL_*`
setting the runs inherit (except the cache paths above), cache identity, durations, and exit status. It contains no game files or cache data.
A run that crashes before writing its report keeps its log and exit code in the manifest.

The manifest identifies the workload with a SHA-256 metadata fingerprint over its sorted relative
file paths, lengths, and UTC modification-time ticks. Only the fingerprint and its algorithm/version
are recorded; the inventory's file names and absolute paths are not persisted. This is a metadata
fingerprint, not a content hash: a content change that preserves the path, length, and modification
time is not detected.

The manifest calls these states **XCL-cold** and **XCL-warm**. GPU driver caches are
driver-controlled and are explicitly recorded as `uncontrolled`; this is not a fully cold-driver
benchmark.

Compare two completed artifact folders without modifying them:

```powershell
.\scripts\perf-compare.ps1 -Baseline 'D:\xcl-perf\main' -Candidate 'D:\xcl-perf\change' > comparison.json
```

The console shows the raw cold/warm duration and exit/timeout state; the redirected JSON keeps
those values and their raw deltas. The tool refuses different workload fingerprints or identity
algorithm/versions, run order, requested duration or startup timeout, runtime environment, system,
GPU, or GPU driver. Missing values are labelled as missing; it does not infer significance or
percentages.

## Tests

```powershell
.\scripts\test.ps1 # cargo build --workspace + cargo test --workspace
.\scripts\perf-run.tests.ps1 # cold/warm runner fixture (no game is run)
.\scripts\perf-compare.tests.ps1 # comparison fixture (synthetic artifacts)
```

Unit tests, an end-to-end test with our own "console title" (`tests/testtitle`) and GPU tests
Expand Down
151 changes: 151 additions & 0 deletions scripts/perf-compare.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Compare two version-1 perf-run artifact folders without changing either one. Concise text goes
# to the host; the success stream is one machine-readable JSON document.
param(
[Parameter(Mandatory = $true)][string]$Baseline,
[Parameter(Mandatory = $true)][string]$Candidate
)
$ErrorActionPreference = 'Stop'

function Read-Json([string]$Path) {
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) { throw "missing artifact: $Path" }
try {
return Get-Content -LiteralPath $Path -Raw -Encoding utf8 | ConvertFrom-Json
} catch {
throw "invalid JSON in $($Path): $($_.Exception.Message)"
}
}

function Has-Property($Object, [string]$Name) {
return $null -ne $Object -and $null -ne $Object.PSObject.Properties[$Name]
}

function Require-Same-Property($Before, $After, [string]$Name, [string]$Description) {
$beforeHas = Has-Property $Before $Name
$afterHas = Has-Property $After $Name
if ($beforeHas -ne $afterHas) { throw "$Description differs; runs are incomparable" }
if ($beforeHas) {
$beforeValue = $Before.$Name | ConvertTo-Json -Compress -Depth 6
$afterValue = $After.$Name | ConvertTo-Json -Compress -Depth 6
if ($beforeValue -ne $afterValue) { throw "$Description differs; runs are incomparable" }
}
}

function Read-Manifest([string]$Root, [string]$Side) {
$manifest = Read-Json (Join-Path $Root 'manifest.json')
if ($manifest.schema -ne 'xcl-perf-run' -or [int]$manifest.version -ne 1) {
throw "$Side has unsupported manifest schema/version"
}
if ($manifest.dirty -ne $false -or $manifest.build.profile -ne 'release') {
throw "$Side is not a clean release run"
}
if ([string]::IsNullOrWhiteSpace([string]$manifest.commit) -or -not (Has-Property $manifest 'environment')) {
throw "$Side manifest is missing commit/environment"
}
if ([string]::IsNullOrWhiteSpace([string]$manifest.workload_id)) {
throw "$Side has no workload_id"
}
if ([string]::IsNullOrWhiteSpace([string]$manifest.workload_id_algorithm) -or
-not (Has-Property $manifest 'workload_id_version') -or ([int]$manifest.workload_id_version -lt 1)) {
throw "$Side has no valid workload identity algorithm/version"
}
$labels = @($manifest.run_order)
if ($labels.Count -ne 2 -or $labels[0] -ne 'xcl-cold' -or $labels[1] -ne 'xcl-warm') {
throw "$Side run_order must be xcl-cold, xcl-warm"
}
$runs = @($manifest.runs)
if ($runs.Count -ne 2) { throw "$Side must contain exactly two run records" }
for ($i = 0; $i -lt 2; $i++) {
if ([int]$runs[$i].order -ne $i + 1 -or $runs[$i].cache_state -ne $labels[$i]) {
throw "$Side run record $($i + 1) does not match run_order"
}
if (-not (Has-Property $runs[$i] 'duration_requested_seconds') -or $null -eq $runs[$i].duration_requested_seconds) {
throw "$Side run record $($i + 1) has no requested duration"
}
}
return $manifest
}

function Number-Or-Null($Object, [string]$Name) {
if ($null -eq $Object -or -not (Has-Property $Object $Name) -or $null -eq $Object.$Name) { return $null }
return [long]$Object.$Name
}

function Delta-Or-Null($Before, $After) {
if ($null -eq $Before -or $null -eq $After) { return $null }
return [long]$After - [long]$Before
}

function Bool-Or-Null($Object, [string]$Name) {
if ($null -eq $Object -or -not (Has-Property $Object $Name) -or $null -eq $Object.$Name) { return $null }
return [bool]$Object.$Name
}

function Display-Value($Value, [string]$Suffix) {
if ($null -eq $Value) { return 'missing' }
return "$Value$Suffix"
}

$baselineRoot = [IO.Path]::GetFullPath($Baseline)
$candidateRoot = [IO.Path]::GetFullPath($Candidate)
$beforeManifest = Read-Manifest $baselineRoot 'baseline'
$afterManifest = Read-Manifest $candidateRoot 'candidate'

if ($beforeManifest.workload_id -cne $afterManifest.workload_id) { throw 'workload_id differs; runs are incomparable' }
if ($beforeManifest.workload_id_algorithm -cne $afterManifest.workload_id_algorithm) {
throw 'workload identity algorithm differs; runs are incomparable'
}
if ([int]$beforeManifest.workload_id_version -ne [int]$afterManifest.workload_id_version) {
throw 'workload identity version differs; runs are incomparable'
}
if ((@($beforeManifest.run_order) -join ',') -ne (@($afterManifest.run_order) -join ',')) { throw 'run order differs; runs are incomparable' }
Require-Same-Property $beforeManifest $afterManifest 'system' 'system information'
if (($beforeManifest.environment | ConvertTo-Json -Compress -Depth 6) -cne ($afterManifest.environment | ConvertTo-Json -Compress -Depth 6)) {
throw 'runtime environment differs; runs are incomparable'
}

$comparisons = @()
for ($i = 0; $i -lt 2; $i++) {
$beforeRun = @($beforeManifest.runs)[$i]
$afterRun = @($afterManifest.runs)[$i]
Require-Same-Property $beforeRun $afterRun 'gpu' "$($beforeRun.cache_state) GPU"
Require-Same-Property $beforeRun $afterRun 'gpu_driver' "$($beforeRun.cache_state) GPU driver"
if ([long]$beforeRun.duration_requested_seconds -ne [long]$afterRun.duration_requested_seconds) {
throw "$($beforeRun.cache_state) requested duration differs; runs are incomparable"
}
Require-Same-Property $beforeRun $afterRun 'startup_timeout_seconds' "$($beforeRun.cache_state) startup timeout"
$beforeDuration = Number-Or-Null $beforeRun 'duration_actual_ms'
$afterDuration = Number-Or-Null $afterRun 'duration_actual_ms'

$comparison = [ordered]@{
label = $beforeRun.cache_state
duration_ms = [ordered]@{
baseline = $beforeDuration
candidate = $afterDuration
delta = Delta-Or-Null $beforeDuration $afterDuration
}
exit_code = [ordered]@{
baseline = Number-Or-Null $beforeRun 'exit_code'
candidate = Number-Or-Null $afterRun 'exit_code'
}
timed_out = [ordered]@{
baseline = Bool-Or-Null $beforeRun 'timed_out'
candidate = Bool-Or-Null $afterRun 'timed_out'
}
}
$comparisons += $comparison

Write-Host "$($comparison.label): duration $(Display-Value $beforeDuration ' ms') -> $(Display-Value $afterDuration ' ms'); delta $(Display-Value $comparison.duration_ms.delta ' ms')"
Write-Host " exit: $(Display-Value $comparison.exit_code.baseline '') -> $(Display-Value $comparison.exit_code.candidate ''); timeout: $(Display-Value $comparison.timed_out.baseline '') -> $(Display-Value $comparison.timed_out.candidate '')"
}

[ordered]@{
schema = 'xcl-perf-comparison'
version = 1
workload_id = $beforeManifest.workload_id
workload_id_algorithm = $beforeManifest.workload_id_algorithm
workload_id_version = [int]$beforeManifest.workload_id_version
run_order = @($beforeManifest.run_order)
baseline = [ordered]@{ commit = $beforeManifest.commit; path = $baselineRoot }
candidate = [ordered]@{ commit = $afterManifest.commit; path = $candidateRoot }
runs = $comparisons
} | ConvertTo-Json -Depth 12
134 changes: 134 additions & 0 deletions scripts/perf-compare.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
$ErrorActionPreference = 'Stop'
$tool = Join-Path $PSScriptRoot 'perf-compare.ps1'
$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-perf-compare-test-' + [guid]::NewGuid())
$baseline = Join-Path $fixture 'baseline'
$candidate = Join-Path $fixture 'candidate'

function Write-Fixture([string]$Root, [string]$Commit, [int]$ColdMs, $WarmMs) {
$null = New-Item -ItemType Directory -Path (Join-Path $Root 'runs\01-cold'), (Join-Path $Root 'runs\02-warm') -Force
$manifest = [ordered]@{
schema = 'xcl-perf-run'
version = 1
commit = $Commit
dirty = $false
build = [ordered]@{ profile = 'release' }
workload_id = 'same-workload'
workload_id_algorithm = 'sha256-relative-path-length-mtime-utc-ticks'
workload_id_version = 1
run_order = @('xcl-cold', 'xcl-warm')
environment = [ordered]@{ XCL_PRESS_AT = '20:A' }
runs = @(
[ordered]@{ order = 1; cache_state = 'xcl-cold'; duration_requested_seconds = 60; startup_timeout_seconds = 120; duration_actual_ms = $ColdMs; exit_code = 0; timed_out = $false },
[ordered]@{ order = 2; cache_state = 'xcl-warm'; duration_requested_seconds = 60; startup_timeout_seconds = 120; duration_actual_ms = $WarmMs; exit_code = $null; timed_out = $true }
)
}
$manifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $Root 'manifest.json') -Encoding utf8
}

try {
Write-Fixture $baseline 'base-commit' 1000 0
Write-Fixture $candidate 'candidate-commit' 850 0

$json = (& $tool -Baseline $baseline -Candidate $candidate | Out-String) | ConvertFrom-Json
if ($json.schema -ne 'xcl-perf-comparison' -or $json.version -ne 1) { throw 'wrong output schema' }
if ($json.workload_id_algorithm -ne 'sha256-relative-path-length-mtime-utc-ticks' -or
$json.workload_id_version -ne 1) { throw 'workload identity contract is missing from output' }
if ($json.runs[0].duration_ms.delta -ne -150) { throw 'cold duration delta is wrong' }
if ($json.runs[1].duration_ms.delta -ne 0) { throw 'zero durations were not compared as raw values' }
if ($json.runs[1].exit_code.candidate -ne $null -or $json.runs[1].timed_out.candidate -ne $true) { throw 'missing exit/timeout was not preserved' }
if (($json | ConvertTo-Json -Depth 12) -match '\b(percent|percentage|ratio|significant|significance)\b') { throw 'output invented a derived significance metric' }

$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.workload_id = 'other-workload'
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'workload_id differs' }
if (-not $refused) { throw 'different workloads were not refused' }

Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.workload_id_algorithm = 'other-algorithm'
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'workload identity algorithm differs' }
if (-not $refused) { throw 'different workload identity algorithms were not refused' }

Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.workload_id_version = 2
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'workload identity version differs' }
if (-not $refused) { throw 'different workload identity versions were not refused' }

Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.runs[1].cache_state = 'xcl-cold'
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'does not match run_order' }
if (-not $refused) { throw 'mismatched run labels were not refused' }

Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.version = 2
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'unsupported manifest schema/version' }
if (-not $refused) { throw 'an unsupported manifest schema was not refused' }

Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest | Add-Member -NotePropertyName system -NotePropertyValue ([pscustomobject]@{ cpu = 'only candidate recorded this' })
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'system information differs' }
if (-not $refused) { throw 'system information present on only one side was not refused' }

Write-Fixture $baseline 'base-commit' 1000 0
Write-Fixture $candidate 'candidate-commit' 850 0
$baselineManifest = Get-Content -LiteralPath (Join-Path $baseline 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$baselineManifest.runs[0] | Add-Member -NotePropertyName gpu -NotePropertyValue 'GPU A'
$candidateManifest.runs[0] | Add-Member -NotePropertyName gpu -NotePropertyValue 'GPU B'
$baselineManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $baseline 'manifest.json') -Encoding utf8
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'xcl-cold GPU differs' }
if (-not $refused) { throw 'different GPUs were not refused' }

Write-Fixture $baseline 'base-commit' 1000 0
Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.runs[1] | Add-Member -NotePropertyName gpu_driver -NotePropertyValue 'only candidate recorded this'
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'xcl-warm GPU driver differs' }
if (-not $refused) { throw 'GPU driver present on only one side was not refused' }

Write-Fixture $baseline 'base-commit' 1000 0
Write-Fixture $candidate 'candidate-commit' 850 0
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest.runs[0].startup_timeout_seconds = 7200
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'xcl-cold startup timeout differs' }
if (-not $refused) { throw 'different startup timeouts were not refused' }

# XCL settings are case-sensitive: XCL_DIRECT_DXIL=all enables direct translation, ALL does not.
Write-Fixture $baseline 'base-commit' 1000 0
Write-Fixture $candidate 'candidate-commit' 850 0
$baselineManifest = Get-Content -LiteralPath (Join-Path $baseline 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$candidateManifest = Get-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
$baselineManifest.environment | Add-Member -NotePropertyName XCL_DIRECT_DXIL -NotePropertyValue 'all'
$candidateManifest.environment | Add-Member -NotePropertyName XCL_DIRECT_DXIL -NotePropertyValue 'ALL'
$baselineManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $baseline 'manifest.json') -Encoding utf8
$candidateManifest | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $candidate 'manifest.json') -Encoding utf8
$refused = $false
try { $null = & $tool -Baseline $baseline -Candidate $candidate } catch { $refused = $_.Exception.Message -match 'runtime environment differs' }
if (-not $refused) { throw 'environments differing only in case were not refused' }

Write-Host 'perf-compare tests: all assertions passed'
} finally {
if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force }
}
Loading
Loading