From f830d4132a07adbe3a78b266704f649eac2babde Mon Sep 17 00:00:00 2001 From: rrrarrra9 <122691427+rrrarrra9@users.noreply.github.com> Date: Wed, 25 Nov 2026 11:29:47 +0100 Subject: [PATCH] Scripts: compare activity memory samples at matching times Report the last complete comparable activity sample from active or finished logs, without sharing their paths. Ignore truncated budget lines and compare sample age with the exact lag limit. Part of #1773. Assisted-by: OpenAI Codex (GPT-6) --- README.md | 3 ++ scripts/activity-memory.ps1 | 61 +++++++++++++++++++++++++++++++ scripts/activity-memory.tests.ps1 | 49 +++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 scripts/activity-memory.ps1 create mode 100644 scripts/activity-memory.tests.ps1 diff --git a/README.md b/README.md index d9d151320a..fa3e5f9b57 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,9 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder `XCL_PSO_TRACE=1` logs every driver compile. A huge compute program the driver refuses is logged with the driver's verdict (`the driver refused the compute PSO of record HASH … with 0x…`): its dispatches are skipped. +- `XCL_ACTIVITY=1` logs process commit and GPU memory each sampling interval. Compare existing + logs with `.\scripts\activity-memory.ps1 -Log main.log,pr.log -AtSeconds 60 -Json`. The script + selects the latest sample at or before that time, flags missing or stale samples and omits log paths. - With `XCL_DRED=1`, a D3D12 device removal logs GPU breadcrumbs in `xcl.log`. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. diff --git a/scripts/activity-memory.ps1 b/scripts/activity-memory.ps1 new file mode 100644 index 0000000000..21cdd74f7f --- /dev/null +++ b/scripts/activity-memory.ps1 @@ -0,0 +1,61 @@ +# Summarize XCL_ACTIVITY=1 memory samples without printing the source logs or their paths. +# Compare two runs at the same elapsed time: +# .\scripts\activity-memory.ps1 -Log main.log,pr.log -AtSeconds 60 -Json +param( + [Parameter(Mandatory = $true, Position = 0)][string[]]$Log, + [ValidateRange(0, 86400)][decimal]$AtSeconds, + [ValidateRange(0, 60)][decimal]$MaxLagSeconds = 3, + [switch]$Json +) +$ErrorActionPreference = 'Stop' + +$atTime = $PSBoundParameters.ContainsKey('AtSeconds') +$culture = [System.Globalization.CultureInfo]::InvariantCulture +$pattern = [regex]('^\[\s*(?\d+(?:\.\d+)?)\]\[\s*\d+\]\[INFO\s*\]\s+memory: ' + + '(?\d+) MB committed by the process; video memory ' + + '(?\d+) MB local(?: \(budget (?\d+) MB\))?, (?\d+) MB non-local; target pages ' + + '(?\d+) MB \(pools (?\d+) MB\); arenas ' + + '(?\d+) MB in use, (?\d+) MB made; sparse pools ' + + '(?\d+) MB \((?\d+) MB mapped\)' + + '(?:; DXGI budget (?\d+) MB local, (?\d+) MB non-local)?$') +$metrics = 'ProcessCommitMiB', 'LocalMiB', 'NonLocalMiB', 'TexturePagesMiB', 'TexturePoolsMiB', + 'ArenasMiB', 'ArenasMadeMiB', 'SparsePoolsMiB', 'SparseMappedMiB', 'LocalBudgetMiB', 'NonLocalBudgetMiB' + +$rows = @(for ($i = 0; $i -lt $Log.Count; $i++) { + $path = (Resolve-Path -LiteralPath $Log[$i]).ProviderPath + $best = $null + $seconds = $null + # XCL can still have the log open for writing when the user takes a sample. + $share = [IO.FileShare]::ReadWrite -bor [IO.FileShare]::Delete + $stream = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, $share) + $reader = [IO.StreamReader]::new($stream) + try { + while ($null -ne ($line = $reader.ReadLine())) { + $match = $pattern.Match($line) + if (-not $match.Success) { continue } + $elapsed = [decimal]::Parse($match.Groups['elapsed'].Value, $culture) + if ($atTime -and $elapsed -gt $AtSeconds) { continue } + if ($null -eq $seconds -or $elapsed -ge $seconds) { + $best = $match + $seconds = $elapsed + } + } + } finally { + $reader.Dispose() + } + $lag = if ($atTime -and $best) { $AtSeconds - $seconds } else { $null } + $status = if (-not $best) { 'no_sample' } elseif ($null -ne $lag -and $lag -gt $MaxLagSeconds) { 'stale' } else { 'ok' } + $row = [ordered]@{ + Input = $i + 1 + RequestedSeconds = if ($atTime) { $AtSeconds } else { $null } + SampleSeconds = $seconds + LagSeconds = $lag + Status = $status + } + foreach ($key in $metrics) { + $row[$key] = if ($status -eq 'ok' -and $best.Groups[$key].Success) { [long]$best.Groups[$key].Value } else { $null } + } + [pscustomobject]$row +}) + +if ($Json) { ConvertTo-Json -InputObject $rows -Compress } else { $rows } diff --git a/scripts/activity-memory.tests.ps1 b/scripts/activity-memory.tests.ps1 new file mode 100644 index 0000000000..df67d56a5f --- /dev/null +++ b/scripts/activity-memory.tests.ps1 @@ -0,0 +1,49 @@ +# Windows PowerShell and pwsh, no GPU required. +$ErrorActionPreference = 'Stop' +$script = Join-Path $PSScriptRoot 'activity-memory.ps1' +$first = [IO.Path]::GetTempFileName() +$second = [IO.Path]::GetTempFileName() +$writer = $null +try { + $line = 'memory: 9137 MB committed by the process; video memory 1300 MB local, 950 MB non-local; target pages 116 MB (pools 128 MB); arenas 93 MB in use, 102 MB made; sparse pools 832 MB (806 MB mapped)' + [IO.File]::WriteAllLines($first, @( + 'G:\private\name\game.exe', + "[ 4.125][ 421][INFO ] $line", + "[ 6.000][ 421][INFO ] $($line.Replace('1300 MB local', '1570 MB local (budget 3344 MB)'))", + '[ 6.900][ 421][INFO ] memory: incomplete sample' + )) + [IO.File]::WriteAllText($second, "[ 2.002][ 421][INFO ] $line; DXGI budget 3344 MB local, 15289 MB non-local") + + # Like an XCL session, allow concurrent readers while holding a write handle. + $writer = [IO.File]::Open($second, [IO.FileMode]::Open, [IO.FileAccess]::Write, [IO.FileShare]::Read) + + $json = & $script -Log $first,$second -AtSeconds 6 -Json + if ($json -match 'private|game\.exe|[\\/]') { throw 'A summary contains a source path' } + $rows = ConvertFrom-Json -InputObject $json + if ($rows.Count -ne 2 -or $rows[0].Input -ne 1 -or $rows[0].Status -ne 'ok' -or $rows[0].LocalMiB -ne 1570) { + throw 'The sample at the requested time was not selected' + } + if ($rows[0].TexturePoolsMiB -ne 128 -or $rows[0].SparseMappedMiB -ne 806 -or $rows[0].ArenasMiB -ne 93 -or $rows[0].ArenasMadeMiB -ne 102 -or $rows[0].LocalBudgetMiB -ne 3344 -or $null -ne $rows[0].NonLocalBudgetMiB) { + throw 'Memory categories were not parsed correctly' + } + if ($rows[1].Status -ne 'stale' -or $null -ne $rows[1].LocalMiB -or $rows[1].LagSeconds -ne 3.998) { + throw 'An old sample was reported as comparable' + } + $earlier = & $script $first -AtSeconds 5 + if ($earlier.SampleSeconds -ne 4.125 -or $earlier.LocalMiB -ne 1300 -or $null -ne $earlier.LocalBudgetMiB) { throw 'A later sample was used' } + $missing = & $script $first -AtSeconds 0 + if ($missing.Status -ne 'no_sample' -or $null -ne $missing.SampleSeconds) { throw 'An absent sample was not reported' } + $strict = & $script $first -AtSeconds 6.0004 -MaxLagSeconds 0 + if ($strict.Status -ne 'stale' -or $strict.LagSeconds -ne 0.0004) { throw 'Rounding made a sample past the lag limit comparable' } + $last = & $script $second + if ($last.Status -ne 'ok' -or $last.SampleSeconds -ne 2.002 -or $last.NonLocalMiB -ne 950 -or $last.LocalBudgetMiB -ne 3344 -or $last.NonLocalBudgetMiB -ne 15289) { throw 'The optional budget suffix was not parsed' } + + [IO.File]::AppendAllText($first, "[ 7.000][ 421][INFO ] $line; DXGI budget 3344 MB local, 15289") + $partial = & $script $first -AtSeconds 7 + if ($partial.SampleSeconds -ne 6 -or $partial.LocalBudgetMiB -ne 3344) { throw 'A truncated budget line displaced the last complete sample' } + 'activity-memory: ok' +} finally { + if ($writer) { $writer.Dispose() } + [IO.File]::Delete($first) + [IO.File]::Delete($second) +}