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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
61 changes: 61 additions & 0 deletions scripts/activity-memory.ps1
Original file line number Diff line number Diff line change
@@ -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*(?<elapsed>\d+(?:\.\d+)?)\]\[\s*\d+\]\[INFO\s*\]\s+memory: ' +
'(?<ProcessCommitMiB>\d+) MB committed by the process; video memory ' +
'(?<LocalMiB>\d+) MB local(?: \(budget (?<LocalBudgetMiB>\d+) MB\))?, (?<NonLocalMiB>\d+) MB non-local; target pages ' +
'(?<TexturePagesMiB>\d+) MB \(pools (?<TexturePoolsMiB>\d+) MB\); arenas ' +
'(?<ArenasMiB>\d+) MB in use, (?<ArenasMadeMiB>\d+) MB made; sparse pools ' +
'(?<SparsePoolsMiB>\d+) MB \((?<SparseMappedMiB>\d+) MB mapped\)' +
'(?:; DXGI budget (?<LocalBudgetMiB>\d+) MB local, (?<NonLocalBudgetMiB>\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 }
49 changes: 49 additions & 0 deletions scripts/activity-memory.tests.ps1
Original file line number Diff line number Diff line change
@@ -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)
}
Loading