From a00c04fc6197b028d9270e996aa2dfe67065067c Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Wed, 25 Nov 2026 20:19:10 -0800 Subject: [PATCH 01/10] Scripts: add reproducible cold and warm performance runs Build a clean locked release and run one workload against fresh ephemeral XCL caches, then the exact same workload against those caches warm. Preserve only logs, reports, and a versioned environment manifest while explicitly leaving the driver cache uncontrolled. Assisted-by: Codex (GPT-5.6-sol) (cherry picked from commit 5bdaa54ee9b9bece2e7867ad183165bcd8d9d11f) Ported without XCL_STALL_TRACE, which comes from the stall module on #2778 and is not on main. --- README.md | 21 ++++ scripts/perf-run.ps1 | 208 +++++++++++++++++++++++++++++++++++++ scripts/perf-run.tests.ps1 | 108 +++++++++++++++++++ 3 files changed, 337 insertions(+) create mode 100644 scripts/perf-run.ps1 create mode 100644 scripts/perf-run.tests.ps1 diff --git a/README.md b/README.md index 1bd0c54868..06a9be53c1 100644 --- a/README.md +++ b/README.md @@ -339,10 +339,31 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder +## 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. 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, selected XCL +environment, cache identity, durations, and exit status. It contains no game files or cache data. + +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. + ## Tests ```powershell .\scripts\test.ps1 # cargo build --workspace + cargo test --workspace +.\scripts\perf-run.tests.ps1 # cold/warm runner fixture (no game is run) ``` Unit tests, an end-to-end test with our own "console title" (`tests/testtitle`) and GPU tests diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 new file mode 100644 index 0000000000..a1f26d6efe --- /dev/null +++ b/scripts/perf-run.ps1 @@ -0,0 +1,208 @@ +# Reproducible paired runtime measurement: an XCL-cold run followed by an XCL-warm run +# against the same ephemeral XCL data and DXIL cache. The GPU driver's own cache is not +# controlled and is named as such in the manifest. +param( + [Parameter(Mandatory = $true)][string]$Game, + [Parameter(Mandatory = $true)][string]$OutDir, + [int]$Seconds = 120 +) +$ErrorActionPreference = 'Stop' + +if ($Seconds -lt 1) { throw '-Seconds must be at least 1' } +if (-not (Test-Path -LiteralPath $Game -PathType Container)) { throw "game folder not found: $Game" } +$gamePath = [IO.Path]::GetFullPath($Game) +$root = Split-Path $PSScriptRoot -Parent + +function Run-Git([string[]]$Arguments) { + $out = @(& git.exe -C $root @Arguments) + if ($LASTEXITCODE -ne 0) { throw "git $($Arguments -join ' ') failed with exit code $LASTEXITCODE" } + return $out +} + +$commit = ((Run-Git -Arguments @('rev-parse', 'HEAD')) -join '').Trim() +$dirtyLines = @(Run-Git -Arguments @('status', '--porcelain', '--untracked-files=all')) +if ($dirtyLines.Count -ne 0) { throw 'perf-run requires a clean worktree so the executable names an exact commit' } + +if (Test-Path -LiteralPath $OutDir) { + if (@(Get-ChildItem -LiteralPath $OutDir -Force).Count -ne 0) { throw "output folder is not empty: $OutDir" } +} else { + $null = New-Item -ItemType Directory -Path $OutDir +} +$outPath = [IO.Path]::GetFullPath($OutDir) + +Push-Location $root +try { + & cargo build --locked --release -p xcl + if ($LASTEXITCODE -ne 0) { throw "release build failed with exit code $LASTEXITCODE" } +} finally { + Pop-Location +} +if (@(Run-Git -Arguments @('status', '--porcelain', '--untracked-files=all')).Count -ne 0) { + throw 'the worktree changed during the release build' +} + +$xcl = Join-Path $root 'target\release\xcl.exe' +# Test scripts use a command file after still exercising the clean-tree and release-build steps. +if ($env:XCL_PERF_RUN_TESTING -eq '1' -and $env:XCL_PERF_RUN_TEST_XCL) { + $xcl = $env:XCL_PERF_RUN_TEST_XCL +} +if (-not (Test-Path -LiteralPath $xcl)) { throw "release build did not produce $xcl" } + +$cacheId = [guid]::NewGuid().ToString('n') +$cacheRoot = Join-Path ([IO.Path]::GetTempPath()) ("xcl-perf-$cacheId") +$dataRoot = Join-Path $cacheRoot 'data' +$dxilCache = Join-Path $cacheRoot 'dxil' +$null = New-Item -ItemType Directory -Path $dataRoot +$null = New-Item -ItemType Directory -Path $dxilCache + +$environmentNames = @( + 'XCL_ACTIVITY', 'XCL_ADAPTER', 'XCL_DEVICE_TYPE', 'XCL_DIRECT_DXIL', + 'XCL_DXC_THREADS', 'XCL_FRAME_INTERVAL_US', 'XCL_HEAP_WINDOWS', + 'XCL_LAZY_PSO', 'XCL_NETWORK', 'XCL_PRESS_AT', 'XCL_PSO_PRELOAD', + 'XCL_REQUIRE_GPU', 'XCL_RUN_SECONDS' +) +$changedNames = @('XCL_ACTIVITY', 'XCL_DATA_ROOT', 'XCL_DXIL_CACHE', 'XCL_NETWORK', 'XCL_RUN_SECONDS') +$savedEnvironment = @{} +foreach ($name in $changedNames) { + $savedEnvironment[$name] = [Environment]::GetEnvironmentVariable($name, 'Process') +} + +function Video-Driver([string]$Adapter) { + try { + $controllers = @(Get-CimInstance Win32_VideoController) + $controller = $controllers | Where-Object { + $Adapter -and ($Adapter.Contains($_.Name) -or $_.Name.Contains($Adapter)) + } | Select-Object -First 1 + if (-not $controller) { $controller = $controllers | Where-Object { $_.Name -notmatch 'Basic' } | Select-Object -First 1 } + return $controller.DriverVersion + } catch { + return $null + } +} + +function Invoke-PerfRun([string]$Mode, [int]$Order) { + $runName = '{0:d2}-{1}' -f $Order, $Mode + $artifactDir = Join-Path (Join-Path $outPath 'runs') $runName + $null = New-Item -ItemType Directory -Path $artifactDir -Force + + $psi = New-Object System.Diagnostics.ProcessStartInfo + if ($xcl -match '\.(cmd|bat)$') { + $psi.FileName = 'cmd.exe' + $psi.Arguments = '/d /c ""' + $xcl + '" run "' + $gamePath + '""' + } else { + $psi.FileName = $xcl + $psi.Arguments = 'run "' + $gamePath + '"' + } + $psi.WorkingDirectory = $root + $psi.UseShellExecute = $false + $psi.CreateNoWindow = $true + $psi.RedirectStandardOutput = $true + $psi.RedirectStandardError = $true + $psi.StandardOutputEncoding = [Text.Encoding]::UTF8 + $psi.StandardErrorEncoding = [Text.Encoding]::UTF8 + + $process = New-Object System.Diagnostics.Process + $process.StartInfo = $psi + $watch = [Diagnostics.Stopwatch]::StartNew() + $null = $process.Start() + $stdoutTask = $process.StandardOutput.ReadToEndAsync() + $stderrTask = $process.StandardError.ReadToEndAsync() + $timedOut = -not $process.WaitForExit(($Seconds + 120) * 1000) + if ($timedOut -and -not $process.HasExited) { $process.Kill() } + $process.WaitForExit() + $watch.Stop() + $stdout = $stdoutTask.Result + $null = $stderrTask.Result + + $logLine = ($stdout -split '\r?\n' | Where-Object { $_ -match '^Log:\s+(.+)$' } | Select-Object -Last 1) + if (-not $logLine) { throw "XCL printed no log path during the $Mode run" } + $log = ($logLine -replace '^Log:\s+', '').Trim() + if (-not (Test-Path -LiteralPath $log)) { throw "XCL's $Mode log does not exist: $log" } + Copy-Item -LiteralPath $log -Destination (Join-Path $artifactDir 'xcl.log') + + $sourceReport = Join-Path (Split-Path $log -Parent) 'report.json' + $reportArtifact = $null + $adapter = $null + if (Test-Path -LiteralPath $sourceReport) { + $reportArtifact = 'report.json' + Copy-Item -LiteralPath $sourceReport -Destination (Join-Path $artifactDir $reportArtifact) + try { + $adapter = ((Get-Content -LiteralPath $sourceReport -Raw -Encoding utf8 | ConvertFrom-Json).d3d12.adapter -replace '\s*\([^()]*VRAM\)$', '') + } catch { } + } + + return [ordered]@{ + order = $Order + cache_state = "xcl-$Mode" + duration_requested_seconds = $Seconds + duration_actual_ms = $watch.ElapsedMilliseconds + exit_code = if ($timedOut) { $null } else { $process.ExitCode } + timed_out = $timedOut + gpu = $adapter + gpu_driver = Video-Driver $adapter + artifacts = [ordered]@{ log = 'xcl.log'; report = $reportArtifact } + } +} + +try { + $env:XCL_DATA_ROOT = $dataRoot + $env:XCL_DXIL_CACHE = $dxilCache + $env:XCL_NETWORK = '0' + $env:XCL_RUN_SECONDS = "$Seconds" + $env:XCL_ACTIVITY = '1' + + $recordedEnvironment = [ordered]@{} + foreach ($name in $environmentNames) { + $recordedEnvironment[$name] = [Environment]::GetEnvironmentVariable($name, 'Process') + } + + $runs = @() + $runs += Invoke-PerfRun 'cold' 1 + $runs += Invoke-PerfRun 'warm' 2 + + $cpu = $null + $windows = $null + try { $cpu = (Get-CimInstance Win32_Processor | Select-Object -First 1).Name } catch { } + try { + $os = Get-CimInstance Win32_OperatingSystem + $windows = "$($os.Caption) $($os.Version) build $($os.BuildNumber)" + } catch { } + $rust = (& rustc -Vv) -join [Environment]::NewLine + if ($LASTEXITCODE -ne 0) { throw 'rustc -Vv failed' } + $sha = [Security.Cryptography.SHA256]::Create() + $workloadId = -join ($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes((Split-Path $gamePath -Leaf).Trim()))[0..7] | ForEach-Object { $_.ToString('x2') }) + $sha.Dispose() + + $manifest = [ordered]@{ + schema = 'xcl-perf-run' + version = 1 + commit = $commit + dirty = $false + build = [ordered]@{ profile = 'release'; command = 'cargo build --locked --release -p xcl' } + workload_id = $workloadId + run_order = @('xcl-cold', 'xcl-warm') + system = [ordered]@{ cpu = $cpu; windows = $windows; rust = $rust } + environment = $recordedEnvironment + cache = [ordered]@{ + identity = $cacheId + xcl_data = 'fresh for cold; same ephemeral directory reused for warm' + dxil = 'fresh for cold; same ephemeral directory reused for warm' + driver = 'uncontrolled' + } + runs = $runs + } + $manifest | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Join-Path $outPath 'manifest.json') -Encoding utf8 + Write-Host "Performance artifacts: $outPath" +} finally { + foreach ($name in $changedNames) { + $old = $savedEnvironment[$name] + if ($null -eq $old) { + Remove-Item -Path "Env:$name" -ErrorAction SilentlyContinue + } else { + Set-Item -Path "Env:$name" -Value $old + } + } + if (Test-Path -LiteralPath $cacheRoot) { + Remove-Item -LiteralPath $cacheRoot -Recurse -Force + } +} diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 new file mode 100644 index 0000000000..f2863fca63 --- /dev/null +++ b/scripts/perf-run.tests.ps1 @@ -0,0 +1,108 @@ +# Run on Windows with powershell.exe or pwsh.exe. Uses a clean temporary repository and mock +# cargo/XCL commands; no game executable is run. +$ErrorActionPreference = 'Stop' +$runnerSource = Join-Path $PSScriptRoot 'perf-run.ps1' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-perf-run-test-' + [guid]::NewGuid()) +$repo = Join-Path $fixture 'repo' +$scripts = Join-Path $repo 'scripts' +$game = Join-Path $fixture 'Mock Game' +$out = Join-Path $fixture 'artifacts' +$bin = Join-Path $fixture 'bin' +$userData = Join-Path $fixture 'user-data' +$userDxil = Join-Path $fixture 'user-dxil' +$cargoMarker = Join-Path $fixture 'cargo.txt' +$mockXcl = Join-Path $bin 'mock-xcl.cmd' +$oldPath = $env:PATH +$oldTest = $env:XCL_PERF_RUN_TESTING +$oldTestXcl = $env:XCL_PERF_RUN_TEST_XCL +$oldData = $env:XCL_DATA_ROOT +$oldDxil = $env:XCL_DXIL_CACHE +$oldPress = $env:XCL_PRESS_AT + +try { + $null = New-Item -ItemType Directory -Path $scripts, $game, $bin, $userData, $userDxil + Copy-Item -LiteralPath $runnerSource -Destination (Join-Path $scripts 'perf-run.ps1') + 'target/' | Set-Content -LiteralPath (Join-Path $repo '.gitignore') -Encoding Ascii + 'not copied' | Set-Content -LiteralPath (Join-Path $game 'game-data.bin') -Encoding Ascii + 'keep' | Set-Content -LiteralPath (Join-Path $userData 'sentinel.txt') -Encoding Ascii + 'keep' | Set-Content -LiteralPath (Join-Path $userDxil 'sentinel.txt') -Encoding Ascii + + @' +@echo off +echo %* > "%MOCK_CARGO_MARKER%" +exit /b 0 +'@ | Set-Content -LiteralPath (Join-Path $bin 'cargo.cmd') -Encoding Ascii + @' +@echo off +echo rustc 1.test +echo host: x86_64-pc-windows-msvc +exit /b 0 +'@ | Set-Content -LiteralPath (Join-Path $bin 'rustc.cmd') -Encoding Ascii + @' +@echo off +set STATE=warm +if not exist "%XCL_DXIL_CACHE%\seen" set STATE=cold +if exist "%XCL_DXIL_CACHE%\seen" goto marker_done +echo seen>"%XCL_DXIL_CACHE%\seen" +:marker_done +if not exist "%XCL_DATA_ROOT%\MockTitle\logs" mkdir "%XCL_DATA_ROOT%\MockTitle\logs" +echo cache=%STATE%>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" +echo {"d3d12":{"adapter":"Mock GPU"}}>"%XCL_DATA_ROOT%\MockTitle\logs\report.json" +echo Log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log +exit /b 0 +'@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii + + & git.exe -C $repo init | Out-Null + & git.exe -C $repo add . + & git.exe -C $repo -c user.name='XCL test' -c user.email='xcl-test@example.invalid' -c commit.gpgsign=false commit -m fixture | Out-Null + if ($LASTEXITCODE -ne 0) { throw 'could not create clean fixture repository' } + + $env:PATH = $bin + [IO.Path]::PathSeparator + $oldPath + $env:MOCK_CARGO_MARKER = $cargoMarker + $env:XCL_PERF_RUN_TESTING = '1' + $env:XCL_PERF_RUN_TEST_XCL = $mockXcl + $env:XCL_DATA_ROOT = $userData + $env:XCL_DXIL_CACHE = $userDxil + $env:XCL_PRESS_AT = '20:A,24:A' + + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $out -Seconds 2 + if ($LASTEXITCODE -ne 0) { throw "perf-run.ps1 exited with $LASTEXITCODE" } + + $manifest = Get-Content -LiteralPath (Join-Path $out 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json + if ($manifest.schema -ne 'xcl-perf-run' -or $manifest.version -ne 1) { throw 'wrong manifest schema/version' } + if ($manifest.dirty -ne $false -or $manifest.build.profile -ne 'release') { throw 'build identity was not recorded' } + if (($manifest.run_order -join ',') -ne 'xcl-cold,xcl-warm') { throw 'run order was not cold then warm' } + if ($manifest.cache.driver -ne 'uncontrolled') { throw 'driver cache was not labelled uncontrolled' } + if ($manifest.environment.XCL_PRESS_AT -ne '20:A,24:A') { throw 'input schedule was not recorded' } + if ($manifest.runs.Count -ne 2 -or $manifest.runs[0].cache_state -ne 'xcl-cold' -or $manifest.runs[1].cache_state -ne 'xcl-warm') { throw 'run records are incomplete' } + if ((Get-Content -LiteralPath (Join-Path $out 'runs\01-cold\xcl.log') -Raw) -notmatch 'cache=cold') { throw 'cold run did not start with a fresh DXIL cache' } + if ((Get-Content -LiteralPath (Join-Path $out 'runs\02-warm\xcl.log') -Raw) -notmatch 'cache=warm') { throw 'warm run did not reuse the cold cache' } + if (-not (Test-Path -LiteralPath (Join-Path $out 'runs\01-cold\report.json')) -or -not (Test-Path -LiteralPath (Join-Path $out 'runs\02-warm\report.json'))) { throw 'reports were not preserved' } + $artifactFiles = @(Get-ChildItem -LiteralPath $out -Recurse -File) + $unexpectedArtifacts = @($artifactFiles | Where-Object { $_.Name -notin @('manifest.json', 'xcl.log', 'report.json') }) + if ($artifactFiles.Count -ne 5 -or $unexpectedArtifacts.Count -ne 0) { throw 'the artifact folder contains something other than logs, reports, and the manifest' } + if ($env:XCL_DATA_ROOT -ne $userData -or $env:XCL_DXIL_CACHE -ne $userDxil) { throw 'the caller environment was not restored' } + if (-not (Test-Path -LiteralPath (Join-Path $userData 'sentinel.txt')) -or -not (Test-Path -LiteralPath (Join-Path $userDxil 'sentinel.txt'))) { throw 'a user cache was touched' } + if (Test-Path -LiteralPath (Join-Path ([IO.Path]::GetTempPath()) ("xcl-perf-$($manifest.cache.identity)"))) { throw 'the ephemeral cache was not removed' } + if ((Get-Content -LiteralPath $cargoMarker -Raw) -notmatch 'build --locked --release -p xcl') { throw 'release build command was not run' } + + Add-Content -LiteralPath (Join-Path $repo '.gitignore') -Value '# dirty' + $refused = $false + try { + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir (Join-Path $fixture 'dirty-out') -Seconds 2 + } catch { + $refused = $_.Exception.Message -match 'clean worktree' + } + if (-not $refused) { throw 'a dirty worktree was not refused' } + + Write-Host 'perf-run tests: all assertions passed' +} finally { + $env:PATH = $oldPath + $env:XCL_PERF_RUN_TESTING = $oldTest + $env:XCL_PERF_RUN_TEST_XCL = $oldTestXcl + $env:XCL_DATA_ROOT = $oldData + $env:XCL_DXIL_CACHE = $oldDxil + $env:XCL_PRESS_AT = $oldPress + Remove-Item Env:MOCK_CARGO_MARKER -ErrorAction SilentlyContinue + if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } +} From cbcd632f62879f01fdcf363c5355d4bc0c925c7d Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Wed, 25 Nov 2026 20:32:22 -0800 Subject: [PATCH 02/10] Scripts: fingerprint performance workloads Identify a workload from a deterministic metadata inventory instead of only its folder name, verify the inventory around each paired run, and require matching identity algorithms in comparisons. Persist no paths or file names and document that the fingerprint is not a content hash. Assisted-by: Codex (GPT-5.6-sol) (cherry picked from commit dfcd4bbba062eb08d305aba507af1ffe7d1cc857) Only the perf-run.ps1 part is taken here: the matching checks in perf-compare.ps1 belong to the comparator, which is not part of this change. --- README.md | 6 ++++ scripts/perf-run.ps1 | 60 +++++++++++++++++++++++++++++++++++--- scripts/perf-run.tests.ps1 | 18 ++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 06a9be53c1..5d4f5d36eb 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,12 @@ changed, or deleted. The output folder contains only each run's `xcl.log` and `r a versioned `manifest.json` with the commit, run order, hardware/toolchain, selected XCL environment, cache identity, durations, and exit status. It contains no game files or cache data. +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. diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index a1f26d6efe..3071aae0a5 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -12,6 +12,55 @@ if ($Seconds -lt 1) { throw '-Seconds must be at least 1' } if (-not (Test-Path -LiteralPath $Game -PathType Container)) { throw "game folder not found: $Game" } $gamePath = [IO.Path]::GetFullPath($Game) $root = Split-Path $PSScriptRoot -Parent +$workloadAlgorithm = 'sha256-relative-path-length-mtime-utc-ticks' +$workloadAlgorithmVersion = 1 + +function Read-InventoryRecords([string]$Path) { + $separators = [char[]]@([IO.Path]::DirectorySeparatorChar, [IO.Path]::AltDirectorySeparatorChar) + $prefix = $Path.TrimEnd($separators) + [IO.Path]::DirectorySeparatorChar + $byPath = @{} + try { + foreach ($file in Get-ChildItem -LiteralPath $Path -Recurse -Force -File -ErrorAction Stop) { + $full = [IO.Path]::GetFullPath($file.FullName) + if (-not $full.StartsWith($prefix, [StringComparison]::OrdinalIgnoreCase)) { + throw "inventory path escaped the game folder" + } + $info = New-Object IO.FileInfo $full + $info.Refresh() + if (-not $info.Exists) { throw "file disappeared during inventory: $($file.Name)" } + $relative = $full.Substring($prefix.Length).Replace([IO.Path]::DirectorySeparatorChar, '/') + if ($byPath.ContainsKey($relative)) { throw "duplicate relative inventory path: $relative" } + $length = $info.Length.ToString([Globalization.CultureInfo]::InvariantCulture) + $ticks = $info.LastWriteTimeUtc.Ticks.ToString([Globalization.CultureInfo]::InvariantCulture) + $byPath[$relative] = '{0}:{1}|{2}|{3}' -f $relative.Length, $relative, $length, $ticks + } + } catch { + throw "cannot create a complete game metadata inventory: $($_.Exception.Message)" + } + if ($byPath.Count -eq 0) { throw 'cannot fingerprint an empty game folder' } + [string[]]$paths = @($byPath.Keys) + [Array]::Sort($paths, [StringComparer]::Ordinal) + return @($paths | ForEach-Object { $byPath[$_] }) +} + +function Get-WorkloadIdentity([string]$Path) { + $first = @(Read-InventoryRecords $Path) + $second = @(Read-InventoryRecords $Path) + if ($first.Count -ne $second.Count) { throw 'game metadata inventory changed while it was read' } + for ($i = 0; $i -lt $first.Count; $i++) { + if ($first[$i] -cne $second[$i]) { throw 'game metadata inventory changed while it was read' } + } + $bytes = [Text.Encoding]::UTF8.GetBytes([string]::Join([char]10, [string[]]$first)) + $sha = [Security.Cryptography.SHA256]::Create() + try { + $id = -join ($sha.ComputeHash($bytes) | ForEach-Object { $_.ToString('x2') }) + } finally { + $sha.Dispose() + } + return [ordered]@{ algorithm = $workloadAlgorithm; version = $workloadAlgorithmVersion; id = $id } +} + +$workloadIdentity = Get-WorkloadIdentity $gamePath function Run-Git([string[]]$Arguments) { $out = @(& git.exe -C $root @Arguments) @@ -169,9 +218,10 @@ try { } catch { } $rust = (& rustc -Vv) -join [Environment]::NewLine if ($LASTEXITCODE -ne 0) { throw 'rustc -Vv failed' } - $sha = [Security.Cryptography.SHA256]::Create() - $workloadId = -join ($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes((Split-Path $gamePath -Leaf).Trim()))[0..7] | ForEach-Object { $_.ToString('x2') }) - $sha.Dispose() + $verifiedWorkloadIdentity = Get-WorkloadIdentity $gamePath + if ($verifiedWorkloadIdentity.id -ne $workloadIdentity.id) { + throw 'game metadata inventory changed during the performance runs' + } $manifest = [ordered]@{ schema = 'xcl-perf-run' @@ -179,7 +229,9 @@ try { commit = $commit dirty = $false build = [ordered]@{ profile = 'release'; command = 'cargo build --locked --release -p xcl' } - workload_id = $workloadId + workload_id = $workloadIdentity.id + workload_id_algorithm = $workloadIdentity.algorithm + workload_id_version = $workloadIdentity.version run_order = @('xcl-cold', 'xcl-warm') system = [ordered]@{ cpu = $cpu; windows = $windows; rust = $rust } environment = $recordedEnvironment diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index f2863fca63..38fb8ce464 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -7,6 +7,8 @@ $repo = Join-Path $fixture 'repo' $scripts = Join-Path $repo 'scripts' $game = Join-Path $fixture 'Mock Game' $out = Join-Path $fixture 'artifacts' +$otherGame = Join-Path (Join-Path $fixture 'other-build') 'Mock Game' +$otherOut = Join-Path $fixture 'other-artifacts' $bin = Join-Path $fixture 'bin' $userData = Join-Path $fixture 'user-data' $userDxil = Join-Path $fixture 'user-dxil' @@ -69,11 +71,18 @@ exit /b 0 if ($LASTEXITCODE -ne 0) { throw "perf-run.ps1 exited with $LASTEXITCODE" } $manifest = Get-Content -LiteralPath (Join-Path $out 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json + $manifestRaw = Get-Content -LiteralPath (Join-Path $out 'manifest.json') -Raw -Encoding utf8 if ($manifest.schema -ne 'xcl-perf-run' -or $manifest.version -ne 1) { throw 'wrong manifest schema/version' } if ($manifest.dirty -ne $false -or $manifest.build.profile -ne 'release') { throw 'build identity was not recorded' } if (($manifest.run_order -join ',') -ne 'xcl-cold,xcl-warm') { throw 'run order was not cold then warm' } if ($manifest.cache.driver -ne 'uncontrolled') { throw 'driver cache was not labelled uncontrolled' } if ($manifest.environment.XCL_PRESS_AT -ne '20:A,24:A') { throw 'input schedule was not recorded' } + if ($manifest.workload_id_algorithm -ne 'sha256-relative-path-length-mtime-utc-ticks' -or + $manifest.workload_id_version -ne 1) { throw 'workload identity algorithm/version was not recorded' } + if ($manifest.workload_id -notmatch '^[0-9a-f]{64}$') { throw 'workload identity is not a full SHA-256 value' } + if ($manifestRaw.Contains($game) -or $manifestRaw.Contains('game-data.bin')) { + throw 'workload inventory details leaked into the manifest' + } if ($manifest.runs.Count -ne 2 -or $manifest.runs[0].cache_state -ne 'xcl-cold' -or $manifest.runs[1].cache_state -ne 'xcl-warm') { throw 'run records are incomplete' } if ((Get-Content -LiteralPath (Join-Path $out 'runs\01-cold\xcl.log') -Raw) -notmatch 'cache=cold') { throw 'cold run did not start with a fresh DXIL cache' } if ((Get-Content -LiteralPath (Join-Path $out 'runs\02-warm\xcl.log') -Raw) -notmatch 'cache=warm') { throw 'warm run did not reuse the cold cache' } @@ -86,6 +95,15 @@ exit /b 0 if (Test-Path -LiteralPath (Join-Path ([IO.Path]::GetTempPath()) ("xcl-perf-$($manifest.cache.identity)"))) { throw 'the ephemeral cache was not removed' } if ((Get-Content -LiteralPath $cargoMarker -Raw) -notmatch 'build --locked --release -p xcl') { throw 'release build command was not run' } + $null = New-Item -ItemType Directory -Path $otherGame -Force + 'a different title build with the same folder leaf' | Set-Content -LiteralPath (Join-Path $otherGame 'game-data.bin') -Encoding Ascii + & (Join-Path $scripts 'perf-run.ps1') -Game $otherGame -OutDir $otherOut -Seconds 2 + if ($LASTEXITCODE -ne 0) { throw "second perf-run.ps1 exited with $LASTEXITCODE" } + $otherManifest = Get-Content -LiteralPath (Join-Path $otherOut 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json + if ($otherManifest.workload_id -eq $manifest.workload_id) { + throw 'different builds with the same folder leaf received the same workload identity' + } + Add-Content -LiteralPath (Join-Path $repo '.gitignore') -Value '# dirty' $refused = $false try { From 644862b52c35362640cf81b0625a44bb84253b78 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:02:14 +0000 Subject: [PATCH 03/10] Scripts: perf-run keeps going when cargo writes to stderr Under Windows PowerShell, when the script's output is redirected (a queued or logged run), every stderr line of a native command becomes an error record, and with $ErrorActionPreference = 'Stop' cargo's first "Compiling" line ended the run before the title started. git and rustc are called the same way. Run them with 'Continue' and check their exit codes, as scripts/test.ps1 does. The fixture's mock cargo now writes to stderr and the first run is redirected, which failed before this change. Co-Authored-By: Claude Opus 5.5 --- scripts/perf-run.ps1 | 14 ++++++++++++-- scripts/perf-run.tests.ps1 | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 3071aae0a5..6d97286361 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -62,7 +62,11 @@ function Get-WorkloadIdentity([string]$Path) { $workloadIdentity = Get-WorkloadIdentity $gamePath +# Native commands run with 'Continue': under Windows PowerShell, when the output is redirected +# (a queued or logged run), each stderr line becomes an error record that 'Stop' would throw on. +# Their exit codes are checked instead. function Run-Git([string[]]$Arguments) { + $ErrorActionPreference = 'Continue' $out = @(& git.exe -C $root @Arguments) if ($LASTEXITCODE -ne 0) { throw "git $($Arguments -join ' ') failed with exit code $LASTEXITCODE" } return $out @@ -81,11 +85,14 @@ $outPath = [IO.Path]::GetFullPath($OutDir) Push-Location $root try { + $ErrorActionPreference = 'Continue' & cargo build --locked --release -p xcl - if ($LASTEXITCODE -ne 0) { throw "release build failed with exit code $LASTEXITCODE" } + $buildExit = $LASTEXITCODE } finally { + $ErrorActionPreference = 'Stop' Pop-Location } +if ($buildExit -ne 0) { throw "release build failed with exit code $buildExit" } if (@(Run-Git -Arguments @('status', '--porcelain', '--untracked-files=all')).Count -ne 0) { throw 'the worktree changed during the release build' } @@ -216,8 +223,11 @@ try { $os = Get-CimInstance Win32_OperatingSystem $windows = "$($os.Caption) $($os.Version) build $($os.BuildNumber)" } catch { } + $ErrorActionPreference = 'Continue' $rust = (& rustc -Vv) -join [Environment]::NewLine - if ($LASTEXITCODE -ne 0) { throw 'rustc -Vv failed' } + $rustExit = $LASTEXITCODE + $ErrorActionPreference = 'Stop' + if ($rustExit -ne 0) { throw 'rustc -Vv failed' } $verifiedWorkloadIdentity = Get-WorkloadIdentity $gamePath if ($verifiedWorkloadIdentity.id -ne $workloadIdentity.id) { throw 'game metadata inventory changed during the performance runs' diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 38fb8ce464..e8162ddba4 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -13,6 +13,7 @@ $bin = Join-Path $fixture 'bin' $userData = Join-Path $fixture 'user-data' $userDxil = Join-Path $fixture 'user-dxil' $cargoMarker = Join-Path $fixture 'cargo.txt' +$runLog = Join-Path $fixture 'run.log' $mockXcl = Join-Path $bin 'mock-xcl.cmd' $oldPath = $env:PATH $oldTest = $env:XCL_PERF_RUN_TESTING @@ -32,6 +33,7 @@ try { @' @echo off echo %* > "%MOCK_CARGO_MARKER%" +>&2 echo synthetic build progress exit /b 0 '@ | Set-Content -LiteralPath (Join-Path $bin 'cargo.cmd') -Encoding Ascii @' @@ -67,8 +69,11 @@ exit /b 0 $env:XCL_DXIL_CACHE = $userDxil $env:XCL_PRESS_AT = '20:A,24:A' - & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $out -Seconds 2 + # Redirected like a queued or logged run: Windows PowerShell then turns native stderr (cargo's + # progress) into error records, which must not stop the script. + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $out -Seconds 2 *> $runLog if ($LASTEXITCODE -ne 0) { throw "perf-run.ps1 exited with $LASTEXITCODE" } + if (-not (Get-Content -LiteralPath $runLog -Raw).Contains('synthetic build progress')) { throw 'native build output was not kept in the redirected log' } $manifest = Get-Content -LiteralPath (Join-Path $out 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json $manifestRaw = Get-Content -LiteralPath (Join-Path $out 'manifest.json') -Raw -Encoding utf8 From c94cdbce4cbd37170a498dcd90611c886fdec264 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:18:06 +0000 Subject: [PATCH 04/10] Scripts: perf-run gives an XCL-cold run time to prepare its shaders With a fresh DXIL cache, `xcl run` prepares every shader of the title before the guest starts, and XCL_RUN_SECONDS counts only from there. On a retail title with 26503 shaders, about 1400 were ready after 181 s on an RTX 2070 SUPER, so the fixed 120 s allowance killed the cold run during preparation. A killed XCL prints no `Log:` line, so the script stopped with neither run recorded. Take -StartupTimeoutSeconds as smoke.ps1 does (same range and default) and record it in each run record. When XCL prints no log path, show its exit code, the timeout state and its output, as smoke.ps1 does. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +++- scripts/perf-run.ps1 | 12 ++++++++---- scripts/perf-run.tests.ps1 | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5d4f5d36eb..c046b37d70 100644 --- a/README.md +++ b/README.md @@ -349,7 +349,9 @@ exact caches warm: ``` The script builds `xcl` in release mode and refuses a dirty worktree or a non-empty output -folder. Both runs use a new temporary `XCL_DATA_ROOT` and `XCL_DXIL_CACHE`; the warm run reuses +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, selected XCL diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 6d97286361..196daf2ea8 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -4,7 +4,10 @@ param( [Parameter(Mandatory = $true)][string]$Game, [Parameter(Mandatory = $true)][string]$OutDir, - [int]$Seconds = 120 + [int]$Seconds = 120, + # Additional time for launcher work such as shader preparation before the guest timer starts. + # An XCL-cold run prepares every shader of the title first, which can take far longer. + [ValidateRange(1,86400)][int]$StartupTimeoutSeconds = 120 ) $ErrorActionPreference = 'Stop' @@ -163,15 +166,15 @@ function Invoke-PerfRun([string]$Mode, [int]$Order) { $null = $process.Start() $stdoutTask = $process.StandardOutput.ReadToEndAsync() $stderrTask = $process.StandardError.ReadToEndAsync() - $timedOut = -not $process.WaitForExit(($Seconds + 120) * 1000) + $timedOut = -not $process.WaitForExit(($Seconds + $StartupTimeoutSeconds) * 1000) if ($timedOut -and -not $process.HasExited) { $process.Kill() } $process.WaitForExit() $watch.Stop() $stdout = $stdoutTask.Result - $null = $stderrTask.Result + $stderr = $stderrTask.Result $logLine = ($stdout -split '\r?\n' | Where-Object { $_ -match '^Log:\s+(.+)$' } | Select-Object -Last 1) - if (-not $logLine) { throw "XCL printed no log path during the $Mode run" } + if (-not $logLine) { throw "XCL printed no log path during the $Mode run (exit code $($process.ExitCode), timed out: $timedOut); its output:`n$stdout`n$stderr" } $log = ($logLine -replace '^Log:\s+', '').Trim() if (-not (Test-Path -LiteralPath $log)) { throw "XCL's $Mode log does not exist: $log" } Copy-Item -LiteralPath $log -Destination (Join-Path $artifactDir 'xcl.log') @@ -191,6 +194,7 @@ function Invoke-PerfRun([string]$Mode, [int]$Order) { order = $Order cache_state = "xcl-$Mode" duration_requested_seconds = $Seconds + startup_timeout_seconds = $StartupTimeoutSeconds duration_actual_ms = $watch.ElapsedMilliseconds exit_code = if ($timedOut) { $null } else { $process.ExitCode } timed_out = $timedOut diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index e8162ddba4..d5e85248b0 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -71,7 +71,7 @@ exit /b 0 # Redirected like a queued or logged run: Windows PowerShell then turns native stderr (cargo's # progress) into error records, which must not stop the script. - & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $out -Seconds 2 *> $runLog + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $out -Seconds 2 -StartupTimeoutSeconds 30 *> $runLog if ($LASTEXITCODE -ne 0) { throw "perf-run.ps1 exited with $LASTEXITCODE" } if (-not (Get-Content -LiteralPath $runLog -Raw).Contains('synthetic build progress')) { throw 'native build output was not kept in the redirected log' } @@ -89,6 +89,7 @@ exit /b 0 throw 'workload inventory details leaked into the manifest' } if ($manifest.runs.Count -ne 2 -or $manifest.runs[0].cache_state -ne 'xcl-cold' -or $manifest.runs[1].cache_state -ne 'xcl-warm') { throw 'run records are incomplete' } + if (@($manifest.runs | Where-Object { $_.startup_timeout_seconds -ne 30 }).Count -ne 0) { throw 'startup timeout was not recorded' } if ((Get-Content -LiteralPath (Join-Path $out 'runs\01-cold\xcl.log') -Raw) -notmatch 'cache=cold') { throw 'cold run did not start with a fresh DXIL cache' } if ((Get-Content -LiteralPath (Join-Path $out 'runs\02-warm\xcl.log') -Raw) -notmatch 'cache=warm') { throw 'warm run did not reuse the cold cache' } if (-not (Test-Path -LiteralPath (Join-Path $out 'runs\01-cold\report.json')) -or -not (Test-Path -LiteralPath (Join-Path $out 'runs\02-warm\report.json'))) { throw 'reports were not preserved' } From 128ee21fcafdec1ecfd3e3f8bc496e6174aff617 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Thu, 26 Nov 2026 21:30:57 +0000 Subject: [PATCH 05/10] Scripts: perf-run keeps the log of a run that crashes before its report When the title crashes before XCL writes report.json, `xcl run` prints "No report - see the log: " instead of "Log: ". perf-run found no log path, stopped, and then deleted the ephemeral data root, so the only record of the crash went with it. This happened on a retail title: an access violation (0xc0000005) during the XCL-cold run's shader preparation, about 25 minutes in. Accept either line, so the crashed run's log is kept and its exit code recorded, as the manifest already allows. The fixture's mock XCL can now crash this way. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + scripts/perf-run.ps1 | 7 +++++-- scripts/perf-run.tests.ps1 | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c046b37d70..c7f7289f6f 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,7 @@ the cold run's directories. They are deleted afterwards, and existing user cache 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, selected XCL environment, 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 diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 196daf2ea8..78154b1ff7 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -173,9 +173,12 @@ function Invoke-PerfRun([string]$Mode, [int]$Order) { $stdout = $stdoutTask.Result $stderr = $stderrTask.Result - $logLine = ($stdout -split '\r?\n' | Where-Object { $_ -match '^Log:\s+(.+)$' } | Select-Object -Last 1) + # A run that ends normally prints `Log: `; one that crashes before writing its report + # prints `No report - see the log: ` instead. Keep that log too: it is the crash record. + $logPattern = '^\s*(?:Log:|No report\b.*\bsee the log:)\s+(.+)$' + $logLine = ($stdout -split '\r?\n' | Where-Object { $_ -match $logPattern } | Select-Object -Last 1) if (-not $logLine) { throw "XCL printed no log path during the $Mode run (exit code $($process.ExitCode), timed out: $timedOut); its output:`n$stdout`n$stderr" } - $log = ($logLine -replace '^Log:\s+', '').Trim() + $log = ($logLine -replace $logPattern, '$1').Trim() if (-not (Test-Path -LiteralPath $log)) { throw "XCL's $Mode log does not exist: $log" } Copy-Item -LiteralPath $log -Destination (Join-Path $artifactDir 'xcl.log') diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index d5e85248b0..80d47da413 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -51,6 +51,11 @@ echo seen>"%XCL_DXIL_CACHE%\seen" :marker_done if not exist "%XCL_DATA_ROOT%\MockTitle\logs" mkdir "%XCL_DATA_ROOT%\MockTitle\logs" echo cache=%STATE%>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" +if not "%MOCK_XCL_CRASH%"=="1" goto no_crash +echo Game exited with code 0xc0000005 (3221225477) +echo No report - see the log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log +exit /b -1073741819 +:no_crash echo {"d3d12":{"adapter":"Mock GPU"}}>"%XCL_DATA_ROOT%\MockTitle\logs\report.json" echo Log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log exit /b 0 @@ -110,6 +115,18 @@ exit /b 0 throw 'different builds with the same folder leaf received the same workload identity' } + # A crash before the report: the log is still kept and the exit code recorded. + $crashOut = Join-Path $fixture 'crash-artifacts' + $env:MOCK_XCL_CRASH = '1' + try { + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $crashOut -Seconds 2 *> $runLog + } finally { + Remove-Item Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue + } + $crashManifest = Get-Content -LiteralPath (Join-Path $crashOut 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json + if ($crashManifest.runs[0].exit_code -ne -1073741819 -or $null -ne $crashManifest.runs[0].artifacts.report) { throw 'a crashed run was not recorded with its exit code and without a report' } + if ((Get-Content -LiteralPath (Join-Path $crashOut 'runs\01-cold\xcl.log') -Raw) -notmatch 'cache=cold') { throw 'the crashed run''s log was not kept' } + Add-Content -LiteralPath (Join-Path $repo '.gitignore') -Value '# dirty' $refused = $false try { @@ -127,6 +144,6 @@ exit /b 0 $env:XCL_DATA_ROOT = $oldData $env:XCL_DXIL_CACHE = $oldDxil $env:XCL_PRESS_AT = $oldPress - Remove-Item Env:MOCK_CARGO_MARKER -ErrorAction SilentlyContinue + Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } } From 72d80c95afa64a205a58f874259a95a88940340c Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:01:48 +0000 Subject: [PATCH 06/10] Scripts: perf-run records every inherited XCL setting The manifest recorded a fixed list of 13 XCL_* variables, while the runtime reads about 180. Two runs that differed in an unlisted switch, such as XCL_PIPELINE_THREADS or XCL_PREPARE_ALL, produced identical environment records and perf-compare accepted the pair (reported on #2888 and #2887). Record every XCL_* variable the runs inherit, sorted by name, except the per-run XCL_DATA_ROOT / XCL_DXIL_CACHE paths the script sets itself and its XCL_PERF_RUN_* test hooks. Co-Authored-By: Claude Opus 5.5 --- scripts/perf-run.ps1 | 15 ++++++++------- scripts/perf-run.tests.ps1 | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 78154b1ff7..47761ce329 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -114,12 +114,9 @@ $dxilCache = Join-Path $cacheRoot 'dxil' $null = New-Item -ItemType Directory -Path $dataRoot $null = New-Item -ItemType Directory -Path $dxilCache -$environmentNames = @( - 'XCL_ACTIVITY', 'XCL_ADAPTER', 'XCL_DEVICE_TYPE', 'XCL_DIRECT_DXIL', - 'XCL_DXC_THREADS', 'XCL_FRAME_INTERVAL_US', 'XCL_HEAP_WINDOWS', - 'XCL_LAZY_PSO', 'XCL_NETWORK', 'XCL_PRESS_AT', 'XCL_PSO_PRELOAD', - 'XCL_REQUIRE_GPU', 'XCL_RUN_SECONDS' -) +# Every XCL_* setting the runs inherit is recorded, since the runtime reads far more switches than a +# list could keep up with. Left out: the per-run cache paths set below and this script's test hooks. +$unrecordedNames = @('XCL_DATA_ROOT', 'XCL_DXIL_CACHE') $changedNames = @('XCL_ACTIVITY', 'XCL_DATA_ROOT', 'XCL_DXIL_CACHE', 'XCL_NETWORK', 'XCL_RUN_SECONDS') $savedEnvironment = @{} foreach ($name in $changedNames) { @@ -215,7 +212,11 @@ try { $env:XCL_ACTIVITY = '1' $recordedEnvironment = [ordered]@{} - foreach ($name in $environmentNames) { + [string[]]$recordedNames = @([Environment]::GetEnvironmentVariables('Process').Keys | + ForEach-Object { ([string]$_).ToUpperInvariant() } | + Where-Object { $_.StartsWith('XCL_') -and -not $_.StartsWith('XCL_PERF_RUN_') -and $_ -notin $unrecordedNames }) + [Array]::Sort($recordedNames, [StringComparer]::Ordinal) + foreach ($name in $recordedNames) { $recordedEnvironment[$name] = [Environment]::GetEnvironmentVariable($name, 'Process') } diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 80d47da413..9fc9772c3c 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -21,6 +21,7 @@ $oldTestXcl = $env:XCL_PERF_RUN_TEST_XCL $oldData = $env:XCL_DATA_ROOT $oldDxil = $env:XCL_DXIL_CACHE $oldPress = $env:XCL_PRESS_AT +$oldPipelineThreads = $env:XCL_PIPELINE_THREADS try { $null = New-Item -ItemType Directory -Path $scripts, $game, $bin, $userData, $userDxil @@ -73,6 +74,7 @@ exit /b 0 $env:XCL_DATA_ROOT = $userData $env:XCL_DXIL_CACHE = $userDxil $env:XCL_PRESS_AT = '20:A,24:A' + $env:XCL_PIPELINE_THREADS = '1' # Redirected like a queued or logged run: Windows PowerShell then turns native stderr (cargo's # progress) into error records, which must not stop the script. @@ -87,6 +89,11 @@ exit /b 0 if (($manifest.run_order -join ',') -ne 'xcl-cold,xcl-warm') { throw 'run order was not cold then warm' } if ($manifest.cache.driver -ne 'uncontrolled') { throw 'driver cache was not labelled uncontrolled' } if ($manifest.environment.XCL_PRESS_AT -ne '20:A,24:A') { throw 'input schedule was not recorded' } + if ($manifest.environment.XCL_PIPELINE_THREADS -ne '1') { throw 'an inherited XCL setting was not recorded' } + $recordedNames = @($manifest.environment.PSObject.Properties.Name) + if (@($recordedNames | Where-Object { $_ -in @('XCL_DATA_ROOT', 'XCL_DXIL_CACHE') -or $_ -like 'XCL_PERF_RUN_*' }).Count -ne 0) { + throw 'per-run cache paths or test hooks were recorded' + } if ($manifest.workload_id_algorithm -ne 'sha256-relative-path-length-mtime-utc-ticks' -or $manifest.workload_id_version -ne 1) { throw 'workload identity algorithm/version was not recorded' } if ($manifest.workload_id -notmatch '^[0-9a-f]{64}$') { throw 'workload identity is not a full SHA-256 value' } @@ -144,6 +151,7 @@ exit /b 0 $env:XCL_DATA_ROOT = $oldData $env:XCL_DXIL_CACHE = $oldDxil $env:XCL_PRESS_AT = $oldPress + $env:XCL_PIPELINE_THREADS = $oldPipelineThreads Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } } From 47e123880e3b63ddbffd71a95667fb059268c33c Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Fri, 27 Nov 2026 09:58:31 +0000 Subject: [PATCH 07/10] Scripts: perf-run launches the executable cargo reports building perf-run built with cargo and then launched the fixed path target\release\xcl.exe. With CARGO_TARGET_DIR (or a cargo config) pointing elsewhere, that path held an older build, and both runs used it while the manifest named the current commit (reported on #2887). The build now asks cargo for JSON messages for the xcl binary and launches the executable its compiler-artifact message names. The fixture's mock cargo reports the mock XCL that way, next to a stale target\release\xcl.exe that the old script launched; the test-only executable override is gone. Co-Authored-By: Claude Opus 5.5 --- scripts/perf-run.ps1 | 19 +++++++++++++------ scripts/perf-run.tests.ps1 | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 47761ce329..8222e0ff31 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -89,7 +89,9 @@ $outPath = [IO.Path]::GetFullPath($OutDir) Push-Location $root try { $ErrorActionPreference = 'Continue' - & cargo build --locked --release -p xcl + # Cargo's JSON messages name the executable it built, wherever CARGO_TARGET_DIR or a config + # puts it; a fixed target\release path could launch an older build. Diagnostics stay on stderr. + $buildMessages = @(& cargo build --locked --release -p xcl --bin xcl --message-format=json-render-diagnostics) $buildExit = $LASTEXITCODE } finally { $ErrorActionPreference = 'Stop' @@ -100,11 +102,16 @@ if (@(Run-Git -Arguments @('status', '--porcelain', '--untracked-files=all')).Co throw 'the worktree changed during the release build' } -$xcl = Join-Path $root 'target\release\xcl.exe' -# Test scripts use a command file after still exercising the clean-tree and release-build steps. -if ($env:XCL_PERF_RUN_TESTING -eq '1' -and $env:XCL_PERF_RUN_TEST_XCL) { - $xcl = $env:XCL_PERF_RUN_TEST_XCL +$xcl = $null +foreach ($line in $buildMessages) { + if (-not ([string]$line).StartsWith('{')) { continue } + $message = $line | ConvertFrom-Json + if ($message.reason -eq 'compiler-artifact' -and $message.target.name -eq 'xcl' -and + @($message.target.kind) -contains 'bin' -and $message.executable) { + $xcl = $message.executable + } } +if (-not $xcl) { throw 'cargo reported no xcl executable for the release build' } if (-not (Test-Path -LiteralPath $xcl)) { throw "release build did not produce $xcl" } $cacheId = [guid]::NewGuid().ToString('n') @@ -246,7 +253,7 @@ try { version = 1 commit = $commit dirty = $false - build = [ordered]@{ profile = 'release'; command = 'cargo build --locked --release -p xcl' } + build = [ordered]@{ profile = 'release'; command = 'cargo build --locked --release -p xcl --bin xcl' } workload_id = $workloadIdentity.id workload_id_algorithm = $workloadIdentity.algorithm workload_id_version = $workloadIdentity.version diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 9fc9772c3c..1c0fb34886 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -13,11 +13,10 @@ $bin = Join-Path $fixture 'bin' $userData = Join-Path $fixture 'user-data' $userDxil = Join-Path $fixture 'user-dxil' $cargoMarker = Join-Path $fixture 'cargo.txt' +$cargoArtifact = Join-Path $fixture 'cargo-artifact.json' $runLog = Join-Path $fixture 'run.log' $mockXcl = Join-Path $bin 'mock-xcl.cmd' $oldPath = $env:PATH -$oldTest = $env:XCL_PERF_RUN_TESTING -$oldTestXcl = $env:XCL_PERF_RUN_TEST_XCL $oldData = $env:XCL_DATA_ROOT $oldDxil = $env:XCL_DXIL_CACHE $oldPress = $env:XCL_PRESS_AT @@ -35,6 +34,7 @@ try { @echo off echo %* > "%MOCK_CARGO_MARKER%" >&2 echo synthetic build progress +type "%MOCK_CARGO_ARTIFACT%" exit /b 0 '@ | Set-Content -LiteralPath (Join-Path $bin 'cargo.cmd') -Encoding Ascii @' @@ -62,6 +62,13 @@ echo Log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log exit /b 0 '@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii + # Cargo reports the executable it built; a stale one at the default target path must not run. + [ordered]@{ reason = 'compiler-artifact'; target = [ordered]@{ name = 'xcl'; kind = @('bin') }; executable = $mockXcl } | + ConvertTo-Json -Compress | Set-Content -LiteralPath $cargoArtifact -Encoding Ascii + $staleXcl = Join-Path $repo 'target\release\xcl.exe' + $null = New-Item -ItemType Directory -Path (Split-Path $staleXcl -Parent) + 'stale build' | Set-Content -LiteralPath $staleXcl -Encoding Ascii + & git.exe -C $repo init | Out-Null & git.exe -C $repo add . & git.exe -C $repo -c user.name='XCL test' -c user.email='xcl-test@example.invalid' -c commit.gpgsign=false commit -m fixture | Out-Null @@ -69,8 +76,7 @@ exit /b 0 $env:PATH = $bin + [IO.Path]::PathSeparator + $oldPath $env:MOCK_CARGO_MARKER = $cargoMarker - $env:XCL_PERF_RUN_TESTING = '1' - $env:XCL_PERF_RUN_TEST_XCL = $mockXcl + $env:MOCK_CARGO_ARTIFACT = $cargoArtifact $env:XCL_DATA_ROOT = $userData $env:XCL_DXIL_CACHE = $userDxil $env:XCL_PRESS_AT = '20:A,24:A' @@ -111,7 +117,7 @@ exit /b 0 if ($env:XCL_DATA_ROOT -ne $userData -or $env:XCL_DXIL_CACHE -ne $userDxil) { throw 'the caller environment was not restored' } if (-not (Test-Path -LiteralPath (Join-Path $userData 'sentinel.txt')) -or -not (Test-Path -LiteralPath (Join-Path $userDxil 'sentinel.txt'))) { throw 'a user cache was touched' } if (Test-Path -LiteralPath (Join-Path ([IO.Path]::GetTempPath()) ("xcl-perf-$($manifest.cache.identity)"))) { throw 'the ephemeral cache was not removed' } - if ((Get-Content -LiteralPath $cargoMarker -Raw) -notmatch 'build --locked --release -p xcl') { throw 'release build command was not run' } + if ((Get-Content -LiteralPath $cargoMarker -Raw) -notmatch 'build --locked --release -p xcl --bin xcl --message-format=json-render-diagnostics') { throw 'release build command was not run' } $null = New-Item -ItemType Directory -Path $otherGame -Force 'a different title build with the same folder leaf' | Set-Content -LiteralPath (Join-Path $otherGame 'game-data.bin') -Encoding Ascii @@ -146,12 +152,10 @@ exit /b 0 Write-Host 'perf-run tests: all assertions passed' } finally { $env:PATH = $oldPath - $env:XCL_PERF_RUN_TESTING = $oldTest - $env:XCL_PERF_RUN_TEST_XCL = $oldTestXcl $env:XCL_DATA_ROOT = $oldData $env:XCL_DXIL_CACHE = $oldDxil $env:XCL_PRESS_AT = $oldPress $env:XCL_PIPELINE_THREADS = $oldPipelineThreads - Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue + Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_CARGO_ARTIFACT, Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } } From e1d70336881bbd67ca303a25e15cc1228eec5644 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Fri, 27 Nov 2026 09:59:25 +0000 Subject: [PATCH 08/10] Scripts: perf-run passes a game folder with a trailing separator intact perf-run quoted the game folder as "". Windows argument parsing halves backslashes that come before a quote, so a folder given as 'D:\Some Game\' reached xcl as 'D:\Some Game"' and the run failed (reported on #2887). The trailing run of backslashes is now doubled. A .cmd mock does not parse its command line that way, so the fixture compiles a small C# shim (with the .NET Framework csc.exe in Windows) that records the arguments it receives and then runs the mock; the old script fails that check. Co-Authored-By: Claude Opus 5.5 --- scripts/perf-run.ps1 | 4 +++- scripts/perf-run.tests.ps1 | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 8222e0ff31..9e0ed44d88 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -154,7 +154,9 @@ function Invoke-PerfRun([string]$Mode, [int]$Order) { $psi.Arguments = '/d /c ""' + $xcl + '" run "' + $gamePath + '""' } else { $psi.FileName = $xcl - $psi.Arguments = 'run "' + $gamePath + '"' + # Windows argument parsing halves backslashes before a quote, so a folder given with a + # trailing separator needs that run doubled or its closing quote becomes part of the path. + $psi.Arguments = 'run "' + ($gamePath -replace '(\\+)$', '$1$1') + '"' } $psi.WorkingDirectory = $root $psi.UseShellExecute = $false diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 1c0fb34886..64023171bd 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -148,6 +148,39 @@ exit /b 0 $refused = $_.Exception.Message -match 'clean worktree' } if (-not $refused) { throw 'a dirty worktree was not refused' } + Set-Content -LiteralPath (Join-Path $repo '.gitignore') -Value 'target/' -Encoding Ascii + + # A real executable parses its command line the way XCL does (a command file does not): a game + # folder with a space and a trailing separator must arrive as given. The shim records its + # arguments, then hands over to the mock. + $nativeXcl = Join-Path $bin 'mock-xcl.exe' + $nativeArgs = Join-Path $fixture 'native-args.txt' + $shimSource = Join-Path $fixture 'shim.cs' + @' +using System; +using System.Diagnostics; +using System.IO; +static class Shim { + static int Main(string[] args) { + File.WriteAllLines(Environment.GetEnvironmentVariable("MOCK_XCL_ARGS"), args); + var cmd = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mock-xcl.cmd"); + var psi = new ProcessStartInfo("cmd.exe", "/d /c \"\"" + cmd + "\"\"") { UseShellExecute = false }; + using (var p = Process.Start(psi)) { p.WaitForExit(); return p.ExitCode; } + } +} +'@ | Set-Content -LiteralPath $shimSource -Encoding Ascii + $csc = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319\csc.exe' + & $csc /nologo /target:exe "/out:$nativeXcl" $shimSource | Out-Null + if ($LASTEXITCODE -ne 0) { throw 'could not compile the native mock' } + [ordered]@{ reason = 'compiler-artifact'; target = [ordered]@{ name = 'xcl'; kind = @('bin') }; executable = $nativeXcl } | + ConvertTo-Json -Compress | Set-Content -LiteralPath $cargoArtifact -Encoding Ascii + $env:MOCK_XCL_ARGS = $nativeArgs + $slashGame = $game + '\' + & (Join-Path $scripts 'perf-run.ps1') -Game $slashGame -OutDir (Join-Path $fixture 'native-artifacts') -Seconds 2 *> $runLog + $received = @(Get-Content -LiteralPath $nativeArgs) + if ($received.Count -ne 2 -or $received[0] -ne 'run' -or $received[1] -ne $slashGame) { + throw "the native launch received [$($received -join '] [')] instead of [run] [$slashGame]" + } Write-Host 'perf-run tests: all assertions passed' } finally { @@ -156,6 +189,6 @@ exit /b 0 $env:XCL_DXIL_CACHE = $oldDxil $env:XCL_PRESS_AT = $oldPress $env:XCL_PIPELINE_THREADS = $oldPipelineThreads - Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_CARGO_ARTIFACT, Env:MOCK_XCL_CRASH -ErrorAction SilentlyContinue + Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_CARGO_ARTIFACT, Env:MOCK_XCL_CRASH, Env:MOCK_XCL_ARGS -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } } From 09f483f68fe47db382d993a3edfd04abe62293ae Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:01:09 +0000 Subject: [PATCH 09/10] Scripts: a perf-run timeout ends the run's whole process tree On a timeout perf-run killed only the launcher it started, stopped the clock, and then waited for the output pipes to close. A child of the launcher that inherited them (the launcher starts its host with handle inheritance) kept running, held the read open and could still write the run's log, which was then copied as if it belonged to the timed run (reported on #2887 with a child writing 5 s into a 2 s run). Each run's launcher is now assigned to a kill-on-close job object, which is terminated when the launcher exits or times out, before the clock stops. Reading the output is bounded to 30 s for a process that escaped the job by starting before the launcher was assigned to it. The fixture adds a mock child that writes the log 5 s after a 2 s timeout; the old script copied that write. Co-Authored-By: Claude Opus 5.5 --- scripts/perf-run.ps1 | 87 ++++++++++++++++++++++++++++++++++---- scripts/perf-run.tests.ps1 | 28 ++++++++++++ 2 files changed, 107 insertions(+), 8 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 9e0ed44d88..0d830bd546 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -143,6 +143,64 @@ function Video-Driver([string]$Adapter) { } } +# A job object that kills its processes when terminated or closed, so a run's whole process tree +# ends with it. +if (-not ('XclPerfRun.KillOnCloseJob' -as [type])) { + Add-Type -TypeDefinition @' +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; +namespace XclPerfRun { + public sealed class KillOnCloseJob : IDisposable { + [StructLayout(LayoutKind.Sequential)] + struct BasicLimitInformation { + public long PerProcessUserTimeLimit, PerJobUserTimeLimit; + public uint LimitFlags; + public UIntPtr MinimumWorkingSetSize, MaximumWorkingSetSize; + public uint ActiveProcessLimit; + public UIntPtr Affinity; + public uint PriorityClass, SchedulingClass; + } + [StructLayout(LayoutKind.Sequential)] + struct ExtendedLimitInformation { + public BasicLimitInformation Basic; + public ulong ReadOperationCount, WriteOperationCount, OtherOperationCount; + public ulong ReadTransferCount, WriteTransferCount, OtherTransferCount; + public UIntPtr ProcessMemoryLimit, JobMemoryLimit, PeakProcessMemoryUsed, PeakJobMemoryUsed; + } + const int ExtendedLimitInformationClass = 9; + const uint KillOnJobClose = 0x2000; + [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr CreateJobObjectW(IntPtr attributes, IntPtr name); + [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetInformationJobObject(IntPtr job, int infoClass, ref ExtendedLimitInformation info, int length); + [DllImport("kernel32.dll", SetLastError = true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process); + [DllImport("kernel32.dll", SetLastError = true)] static extern bool TerminateJobObject(IntPtr job, uint exitCode); + [DllImport("kernel32.dll", SetLastError = true)] static extern bool CloseHandle(IntPtr handle); + IntPtr handle; + public KillOnCloseJob() { + handle = CreateJobObjectW(IntPtr.Zero, IntPtr.Zero); + if (handle == IntPtr.Zero) throw new Win32Exception(); + var info = new ExtendedLimitInformation(); + info.Basic.LimitFlags = KillOnJobClose; + if (!SetInformationJobObject(handle, ExtendedLimitInformationClass, ref info, Marshal.SizeOf(typeof(ExtendedLimitInformation)))) { + var error = new Win32Exception(); + Dispose(); + throw error; + } + } + public void Add(IntPtr process) { + if (!AssignProcessToJobObject(handle, process)) throw new Win32Exception(); + } + public void Terminate() { + if (!TerminateJobObject(handle, 1)) throw new Win32Exception(); + } + public void Dispose() { + if (handle != IntPtr.Zero) { CloseHandle(handle); handle = IntPtr.Zero; } + } + } +} +'@ +} + function Invoke-PerfRun([string]$Mode, [int]$Order) { $runName = '{0:d2}-{1}' -f $Order, $Mode $artifactDir = Join-Path (Join-Path $outPath 'runs') $runName @@ -168,14 +226,27 @@ function Invoke-PerfRun([string]$Mode, [int]$Order) { $process = New-Object System.Diagnostics.Process $process.StartInfo = $psi - $watch = [Diagnostics.Stopwatch]::StartNew() - $null = $process.Start() - $stdoutTask = $process.StandardOutput.ReadToEndAsync() - $stderrTask = $process.StandardError.ReadToEndAsync() - $timedOut = -not $process.WaitForExit(($Seconds + $StartupTimeoutSeconds) * 1000) - if ($timedOut -and -not $process.HasExited) { $process.Kill() } - $process.WaitForExit() - $watch.Stop() + $job = New-Object XclPerfRun.KillOnCloseJob + try { + $watch = [Diagnostics.Stopwatch]::StartNew() + $null = $process.Start() + $job.Add($process.Handle) + $stdoutTask = $process.StandardOutput.ReadToEndAsync() + $stderrTask = $process.StandardError.ReadToEndAsync() + $timedOut = -not $process.WaitForExit(($Seconds + $StartupTimeoutSeconds) * 1000) + # Ends the launcher and everything it started, so that no process left behind keeps + # writing the run's log or holds its output pipes open after the run is timed. + $job.Terminate() + $process.WaitForExit() + $watch.Stop() + } finally { + $job.Dispose() + } + # A process that escaped the job (started before the launcher was assigned to it) could still + # hold the pipes; do not wait for it indefinitely. + if (-not $stdoutTask.Wait(30000) -or -not $stderrTask.Wait(30000)) { + throw "the $Mode run's output was still open 30 s after XCL ended" + } $stdout = $stdoutTask.Result $stderr = $stderrTask.Result diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 64023171bd..5167dd425b 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -59,8 +59,17 @@ exit /b -1073741819 :no_crash echo {"d3d12":{"adapter":"Mock GPU"}}>"%XCL_DATA_ROOT%\MockTitle\logs\report.json" echo Log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log +if not "%MOCK_XCL_LINGER%"=="1" exit /b 0 +start "" /b cmd /d /c ""%~dp0mock-child.cmd"" +ping -n 11 127.0.0.1 >nul exit /b 0 '@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii + # Started by the mock and sharing its output: writes the log 5 s later unless it is ended. + @' +@echo off +ping -n 6 127.0.0.1 >nul +echo late child write>>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" +'@ | Set-Content -LiteralPath (Join-Path $bin 'mock-child.cmd') -Encoding Ascii # Cargo reports the executable it built; a stale one at the default target path must not run. [ordered]@{ reason = 'compiler-artifact'; target = [ordered]@{ name = 'xcl'; kind = @('bin') }; executable = $mockXcl } | @@ -140,6 +149,25 @@ exit /b 0 if ($crashManifest.runs[0].exit_code -ne -1073741819 -or $null -ne $crashManifest.runs[0].artifacts.report) { throw 'a crashed run was not recorded with its exit code and without a report' } if ((Get-Content -LiteralPath (Join-Path $crashOut 'runs\01-cold\xcl.log') -Raw) -notmatch 'cache=cold') { throw 'the crashed run''s log was not kept' } + # A timeout ends the whole process tree: a child of the launcher does not outlive the run, + # keep its output open or write the log after the run's time is taken. + $lingerOut = Join-Path $fixture 'linger-artifacts' + $env:MOCK_XCL_LINGER = '1' + try { + & (Join-Path $scripts 'perf-run.ps1') -Game $game -OutDir $lingerOut -Seconds 1 -StartupTimeoutSeconds 1 *> $runLog + } finally { + Remove-Item Env:MOCK_XCL_LINGER -ErrorAction SilentlyContinue + } + $lingerManifest = Get-Content -LiteralPath (Join-Path $lingerOut 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json + foreach ($run in $lingerManifest.runs) { + if (-not $run.timed_out -or $run.duration_actual_ms -ge 4000) { throw "a timed-out run was not ended at its deadline: $($run.duration_actual_ms) ms" } + } + foreach ($runName in @('01-cold', '02-warm')) { + if ((Get-Content -LiteralPath (Join-Path $lingerOut "runs\$runName\xcl.log") -Raw) -match 'late child write') { + throw "a process left by the $runName run wrote its log after the timeout" + } + } + Add-Content -LiteralPath (Join-Path $repo '.gitignore') -Value '# dirty' $refused = $false try { From 99acc436d6b02c69486b7223e8ba1557a1facf52 Mon Sep 17 00:00:00 2001 From: KOLESNiii <102358205+KOLESNiii@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:15:21 +0000 Subject: [PATCH 10/10] Scripts: perf-run's fixture checks XCL_PREPARE_ALL reaches the manifest XCL_PREPARE_ALL (prepare every shader record rather than only the title's used-shader list) was the switch reported missing from the manifest on #2887; the fixture now sets it and checks it is recorded. README says the manifest holds every inherited XCL_* setting instead of a selected list. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 ++-- scripts/perf-run.tests.ps1 | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7f7289f6f..f222be1a95 100644 --- a/README.md +++ b/README.md @@ -354,8 +354,8 @@ the title, which can take far longer than the default two minutes allowed for st `-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, selected XCL -environment, cache identity, durations, and exit status. It contains no game files or cache data. +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 diff --git a/scripts/perf-run.tests.ps1 b/scripts/perf-run.tests.ps1 index 5167dd425b..f543a4a482 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -21,6 +21,7 @@ $oldData = $env:XCL_DATA_ROOT $oldDxil = $env:XCL_DXIL_CACHE $oldPress = $env:XCL_PRESS_AT $oldPipelineThreads = $env:XCL_PIPELINE_THREADS +$oldPrepareAll = $env:XCL_PREPARE_ALL try { $null = New-Item -ItemType Directory -Path $scripts, $game, $bin, $userData, $userDxil @@ -90,6 +91,7 @@ echo late child write>>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" $env:XCL_DXIL_CACHE = $userDxil $env:XCL_PRESS_AT = '20:A,24:A' $env:XCL_PIPELINE_THREADS = '1' + $env:XCL_PREPARE_ALL = '1' # Redirected like a queued or logged run: Windows PowerShell then turns native stderr (cargo's # progress) into error records, which must not stop the script. @@ -105,6 +107,7 @@ echo late child write>>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" if ($manifest.cache.driver -ne 'uncontrolled') { throw 'driver cache was not labelled uncontrolled' } if ($manifest.environment.XCL_PRESS_AT -ne '20:A,24:A') { throw 'input schedule was not recorded' } if ($manifest.environment.XCL_PIPELINE_THREADS -ne '1') { throw 'an inherited XCL setting was not recorded' } + if ($manifest.environment.XCL_PREPARE_ALL -ne '1') { throw 'the shader preparation switch was not recorded' } $recordedNames = @($manifest.environment.PSObject.Properties.Name) if (@($recordedNames | Where-Object { $_ -in @('XCL_DATA_ROOT', 'XCL_DXIL_CACHE') -or $_ -like 'XCL_PERF_RUN_*' }).Count -ne 0) { throw 'per-run cache paths or test hooks were recorded' @@ -217,6 +220,7 @@ static class Shim { $env:XCL_DXIL_CACHE = $oldDxil $env:XCL_PRESS_AT = $oldPress $env:XCL_PIPELINE_THREADS = $oldPipelineThreads + $env:XCL_PREPARE_ALL = $oldPrepareAll Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_CARGO_ARTIFACT, Env:MOCK_XCL_CRASH, Env:MOCK_XCL_ARGS -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } }