fix(agc): profile completed CPU copies with their actual spans #4187

Merged
Scramblrrrr merged 1 commit from upstream-pr/4187 into main 2026-10-13 04:54:31 +00:00
Scramblrrrr commented 2026-10-12 00:55:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T00:55:43Z.


What

CPU-copy profiling currently counts each region's logical size before sparse allocation clamps it, so a 512 MiB sparse heap can be reported as 512 MiB copied even when its buffer and read are much smaller. Count completed copy operations after copying and report logical spans, buffer spans and actual read bytes separately. Reason and address-bucket totals use buffer spans. Zero-filled gaps are not counted as bytes read.

These are accumulated per-operation totals, not unique allocation sizes or resident memory. Copy behavior and sparse-clamp policy are unchanged; #2992 already implements sparse heap trimming.

Tested

Windows 11 Pro 26200, GCC 15.2 Release, RTX 5070 Ti, required Vulkan, main 7a84b222 plus head 875d7301168330b3d2842e1d2a244979a63e9df3: agc_driver_graphics and agc_driver_bda_device passed 2/2 in 5.91 seconds. Conventions and diff checks pass. Fixture checks use ordinary settings: the graphics mock lacks the profiling query-pool function.

Actual 007 profiling with the identical change carried on rendering head 247de1151e0a53a68c3dbf3445ce134ff5a9cc8f, APS5_PROFILE_DRAW=1: after 33,000 completed CPU-copy operations the log reports 10,398,938 MiB logical spans versus 248,082 MiB buffer spans/bytes read. This validates the distinction, not a performance improvement or a current-main title success. Title files/captures remain local. No full-suite or Linux claim.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823668028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4187). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T00:55:43Z. --- ### What CPU-copy profiling currently counts each region's logical size before sparse allocation clamps it, so a 512 MiB sparse heap can be reported as 512 MiB copied even when its buffer and read are much smaller. Count completed copy operations after copying and report logical spans, buffer spans and actual read bytes separately. Reason and address-bucket totals use buffer spans. Zero-filled gaps are not counted as bytes read. These are accumulated per-operation totals, not unique allocation sizes or resident memory. Copy behavior and sparse-clamp policy are unchanged; #2992 already implements sparse heap trimming. ### Tested Windows 11 Pro 26200, GCC 15.2 Release, RTX 5070 Ti, required Vulkan, main `7a84b222` plus head `875d7301168330b3d2842e1d2a244979a63e9df3`: `agc_driver_graphics` and `agc_driver_bda_device` passed 2/2 in 5.91 seconds. Conventions and diff checks pass. Fixture checks use ordinary settings: the graphics mock lacks the profiling query-pool function. Actual 007 profiling with the identical change carried on rendering head `247de1151e0a53a68c3dbf3445ce134ff5a9cc8f`, `APS5_PROFILE_DRAW=1`: after 33,000 completed CPU-copy operations the log reports 10,398,938 MiB logical spans versus 248,082 MiB buffer spans/bytes read. This validates the distinction, not a performance improvement or a current-main title success. Title files/captures remain local. No full-suite or Linux claim. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Codex)
Dextroid17 commented 2026-10-12 01:18:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T01:18:56Z.


This is cleanly metrics-only — every new or moved statement is counter bookkeeping; the sparse-allocation clamp, the staged-copy path, and every side-effecting call are untouched with identical arguments. The zero-filled-gap exclusion is structurally determined (it walks region.backed, the region's actual committed guest ranges) rather than inspecting byte values, which is the right way to do it — a real zero byte in committed memory still counts as read.

One nuance worth naming, already acknowledged in spirit by the body's "accumulated per-operation totals" framing: moving the count to after the copy means a copy that throws partway now contributes to none of the totals, where it previously counted toward the attempt before failing. That's fine here because nothing in the driver branches on these counters — they only feed a diagnostic print — but it does mean a before/after comparison of these logs across versions isn't apples-to-apples for interrupted copies specifically.

Thread-safety is consistent with what was already there: the new accumulators are either call-local or guarded by the same mutex the pre-existing counters used, and nothing new is held across that lock acquisition.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116050217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4187#issuecomment-6116050217). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T01:18:56Z. --- This is cleanly metrics-only — every new or moved statement is counter bookkeeping; the sparse-allocation clamp, the staged-copy path, and every side-effecting call are untouched with identical arguments. The zero-filled-gap exclusion is structurally determined (it walks `region.backed`, the region's actual committed guest ranges) rather than inspecting byte values, which is the right way to do it — a real zero byte in committed memory still counts as read. One nuance worth naming, already acknowledged in spirit by the body's "accumulated per-operation totals" framing: moving the count to after the copy means a copy that throws partway now contributes to none of the totals, where it previously counted toward the attempt before failing. That's fine here because nothing in the driver branches on these counters — they only feed a diagnostic print — but it does mean a before/after comparison of these logs across versions isn't apples-to-apples for interrupted copies specifically. Thread-safety is consistent with what was already there: the new accumulators are either call-local or guarded by the same mutex the pre-existing counters used, and nothing new is held across that lock acquisition. Written with AI assistance.
Scramblrrrr commented 2026-10-12 14:13:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:13:04Z.


Thanks for checking the accounting and locking. Agreed on the interrupted-copy distinction: an operation that throws before completion contributes to none of the new totals, even if it performed a partial read. These counters describe completed operations and are diagnostic only; they do not control copying or allocation. I will keep that qualification explicit when comparing profiler logs across versions. No performance change claimed here. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6126032255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4187#issuecomment-6126032255). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T14:13:04Z. --- Thanks for checking the accounting and locking. Agreed on the interrupted-copy distinction: an operation that throws before completion contributes to none of the new totals, even if it performed a partial read. These counters describe completed operations and are diagnostic only; they do not control copying or allocation. I will keep that qualification explicit when comparing profiler logs across versions. No performance change claimed here. AI-assisted: Codex.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4187
No description provided.