From 79a3b7a2218a7020c7191f98b0dff08dc0598ec0 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 1/7] 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 9c5aa3fe99..0e37d34f90 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -80,7 +80,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 @@ -115,11 +119,14 @@ $cargoArguments += '--target-dir', $cargoTargetPath Push-Location $root try { + $ErrorActionPreference = 'Continue' & cargo @cargoArguments - 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' } @@ -255,8 +262,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 986ddb05db..0a0d90f674 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -15,6 +15,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 @@ -36,6 +37,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 @' @@ -74,8 +76,11 @@ exit /b 0 $env:XCL_GPU_TIMING = 'caller-value' $env:XCL_GPU_TIMING_MS = '999' - & (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 b12c1f413c1fb4c10eb310e5b82d8aae26fa0ddc 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 2/7] 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 05e3e63d1f..0afda3339a 100644 --- a/README.md +++ b/README.md @@ -446,7 +446,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 0e37d34f90..e8be5cff94 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -6,7 +6,10 @@ param( [Parameter(Mandatory = $true)][string]$OutDir, [int]$Seconds = 120, [string[]]$CargoFeatures = @(), - [string]$CargoTargetDir + [string]$CargoTargetDir, + # 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' @@ -199,15 +202,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') @@ -227,6 +230,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 0a0d90f674..605d098d25 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -78,7 +78,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' } @@ -99,6 +99,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 ((Get-Content -LiteralPath (Join-Path $out 'runs\01-cold\xcl.log') -Raw) -notmatch 'gpu_timing=1 threshold=50') { From 5998d4e76cffd0a552ccb3ee7ccb29faa895eb66 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 3/7] 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 0afda3339a..3253ce8791 100644 --- a/README.md +++ b/README.md @@ -453,6 +453,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 e8be5cff94..6308af6a24 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -209,9 +209,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 605d098d25..4d7b751934 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -56,6 +56,11 @@ echo seen>"%XCL_DXIL_CACHE%\seen" 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 gpu_timing=%XCL_GPU_TIMING% threshold=%XCL_GPU_TIMING_MS%>>"%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","submissions":2,"slowest_submission_ms":1.5,"slowest_submission_lists":3}}>"%XCL_DATA_ROOT%\MockTitle\logs\report.json" echo Log: %XCL_DATA_ROOT%\MockTitle\logs\xcl.log exit /b 0 @@ -146,6 +151,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 { @@ -165,6 +182,6 @@ exit /b 0 $env:XCL_PRESS_AT = $oldPress $env:XCL_GPU_TIMING = $oldGpuTiming $env:XCL_GPU_TIMING_MS = $oldGpuTimingMs - 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 3e9f05bf2da78309784eadc29d65e134bd34052e 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 4/7] 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 6308af6a24..8b08cc2ea5 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -149,14 +149,11 @@ $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_GPU_TIMING', 'XCL_GPU_TIMING_MS', 'XCL_LAZY_PSO', 'XCL_NETWORK', 'XCL_PRESS_AT', 'XCL_PSO_PRELOAD', - 'XCL_REQUIRE_GPU', 'XCL_RUN_SECONDS', 'XCL_STALL_TRACE' -) $changedNames = @('XCL_ACTIVITY', 'XCL_DATA_ROOT', 'XCL_DXIL_CACHE', 'XCL_GPU_TIMING', 'XCL_GPU_TIMING_MS', 'XCL_NETWORK', 'XCL_RUN_SECONDS', 'XCL_STALL_TRACE') +# 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') $savedEnvironment = @{} foreach ($name in $changedNames) { $savedEnvironment[$name] = [Environment]::GetEnvironmentVariable($name, 'Process') @@ -254,7 +251,11 @@ try { $env:XCL_STALL_TRACE = '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 4d7b751934..a1de2c237e 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -25,6 +25,7 @@ $oldDxil = $env:XCL_DXIL_CACHE $oldPress = $env:XCL_PRESS_AT $oldGpuTiming = $env:XCL_GPU_TIMING $oldGpuTimingMs = $env:XCL_GPU_TIMING_MS +$oldPipelineThreads = $env:XCL_PIPELINE_THREADS try { $null = New-Item -ItemType Directory -Path $scripts, $game, $bin, $userData, $userDxil @@ -80,6 +81,7 @@ exit /b 0 $env:XCL_PRESS_AT = '20:A,24:A' $env:XCL_GPU_TIMING = 'caller-value' $env:XCL_GPU_TIMING_MS = '999' + $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. @@ -97,6 +99,11 @@ exit /b 0 if ($manifest.environment.XCL_GPU_TIMING -ne '1' -or $manifest.environment.XCL_GPU_TIMING_MS -ne '50') { throw 'submission timing settings were not forced and 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' } @@ -182,6 +189,7 @@ exit /b 0 $env:XCL_PRESS_AT = $oldPress $env:XCL_GPU_TIMING = $oldGpuTiming $env:XCL_GPU_TIMING_MS = $oldGpuTimingMs + $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 62daa86c73b55be5d9d6c1525da27328f1c532f3 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 5/7] 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 | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/scripts/perf-run.ps1 b/scripts/perf-run.ps1 index 8b08cc2ea5..665fc5afe0 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -183,7 +183,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 a1de2c237e..2f2189d04c 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -178,6 +178,38 @@ 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' } + $env:XCL_PERF_RUN_TEST_XCL = $nativeXcl + $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 { @@ -190,6 +222,6 @@ exit /b 0 $env:XCL_GPU_TIMING = $oldGpuTiming $env:XCL_GPU_TIMING_MS = $oldGpuTimingMs $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_XCL_CRASH, Env:MOCK_XCL_ARGS -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } } From d538c19e5d47c95bc1f1eedeec62cb9e9d3e25e1 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 6/7] 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 665fc5afe0..7194e4460b 100644 --- a/scripts/perf-run.ps1 +++ b/scripts/perf-run.ps1 @@ -172,6 +172,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 @@ -197,14 +255,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 2f2189d04c..ba590039fd 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -64,8 +64,17 @@ exit /b -1073741819 :no_crash echo {"d3d12":{"adapter":"Mock GPU","submissions":2,"slowest_submission_ms":1.5,"slowest_submission_lists":3}}>"%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 & git.exe -C $repo init | Out-Null & git.exe -C $repo add . @@ -170,6 +179,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 3b8a7d7ad98b74491e2caba27b30cb85487217a5 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 7/7] 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 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 3253ce8791..06987f5891 100644 --- a/README.md +++ b/README.md @@ -451,8 +451,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 ba590039fd..d702e953c5 100644 --- a/scripts/perf-run.tests.ps1 +++ b/scripts/perf-run.tests.ps1 @@ -26,6 +26,7 @@ $oldPress = $env:XCL_PRESS_AT $oldGpuTiming = $env:XCL_GPU_TIMING $oldGpuTimingMs = $env:XCL_GPU_TIMING_MS $oldPipelineThreads = $env:XCL_PIPELINE_THREADS +$oldPrepareAll = $env:XCL_PREPARE_ALL try { $null = New-Item -ItemType Directory -Path $scripts, $game, $bin, $userData, $userDxil @@ -91,6 +92,7 @@ echo late child write>>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" $env:XCL_GPU_TIMING = 'caller-value' $env:XCL_GPU_TIMING_MS = '999' $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. @@ -109,6 +111,7 @@ echo late child write>>"%XCL_DATA_ROOT%\MockTitle\logs\xcl.log" throw 'submission timing settings were not forced and 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' @@ -250,6 +253,7 @@ static class Shim { $env:XCL_GPU_TIMING = $oldGpuTiming $env:XCL_GPU_TIMING_MS = $oldGpuTimingMs $env:XCL_PIPELINE_THREADS = $oldPipelineThreads + $env:XCL_PREPARE_ALL = $oldPrepareAll Remove-Item Env:MOCK_CARGO_MARKER, Env:MOCK_XCL_CRASH, Env:MOCK_XCL_ARGS -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } }