feat(agc): record a present window as a Chrome trace and a summary line #4526
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4526"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T14:32:23Z.
Step 1 of #4477. A window of presents is recorded as a Chrome trace-event file plus one summary line, so perf numbers in issues and PRs come from the same capture. The GPU track, the compile threads and the perf templates are follow-ups.
What
APS5_TRACE_FRAMES=<start>:<count>records<count>presents from present<start>(counted from 0).APS5_TRACE_SECONDS=<start>:<length>records from the first present at least<start>s after the first present until the first present<length>s later. The window opens and closes at a present. A malformed value, or both switches together, fails the first present.PerformanceTimeralready brackets the driver's phases with theFrameTimingkeys. While the window is open, a timer on a queue worker or on the presenter also records its scope and eachMarkstage as a complete event (ph:X):Driver.WorkerWait,Driver.Packet,Driver.Packet.draw,Graphics.Draw,Recorder.Submit,Driver.Present,Driver.Present.inflight_wait,Vulkan.Retire, and so on. Each present is a globalpresentinstant with its number. The thread tracks use the existing thread roles (queue worker 0x0,presenter).trace_dropped. Every slice is added to a per-thread total by scope and stage; a slice under 20 us is not written, and its time goes to the thread's counter<thread> folded(ms per present).ProfileOutputof its own (the existing one writes to stderr) gzips it on its writer thread toaps5-trace-<commit>-<pid>.json.gzand appends the summary line toaps5-summary.jsonl, both inAPS5_TRACE_DIRor the working directory. The deflate stream comes from the zlib that libjpeg-turbo already builds from source (the onelibSceZliblinks), so there is no new submodule. That zlib is built withNO_GZIP, soTraceFilewrites the gzip header and the CRC-32 and size trailer itself.commit,dirty,env(everyAPS5_*; a value containing/or\is written as<path>),gpu,driver(VkPhysicalDeviceDriverPropertiesname and info),os,resolution(the video output's),window,presents,frame_ms{p50, p90, p99, max} of the intervals between presents,gpu_busy_ms_per_present(the batch timestamps behind[present]),worker_busy_pctper queue worker (share of the window inDriver.Packet,Driver.Suspend,Driver.EndSubmission,Driver.RewindandDriver.Completion, the non-wait part ofFrameTiming's worker accounting),top_phases_ms_per_frame(the eight largest scopes and stages, withoutDriver.WorkerWait),trace_droppedandtrace.commitanddirtycome from a header that a build step regenerates from git on every build (trace_revision.cmake, rewritten only when it changes), so an incremental build never reports a stale commit.PerformanceTimerdoes one relaxed load and one more null check, and nothing is allocated. With a switch set, the recorder writes the batch timestamp pair for the whole run, as withAPS5_PROFILE_DRAW, sogpu_busy_ms_per_presentneeds no profile switch.docs/dev/BUILD.md(Performance trace).Not in this step: the GPU track, compile threads,
Submission.*and lock-site events, a batches-in-flight counter, the templates. From the questions in #4477: the window defaults to presents, and the summary goes only intoaps5-summary.jsonl, not into the trace.Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release.
agc_performance_trace(new): window edges by frames and by seconds, rejected values, the buffer cap and the dropped flag, folding of short slices and the per-present counter, JSON string escaping, the exact JSON of a small thread, every summary field, a written.json.gzinflated and checked against its CRC-32 and size, and appended summary lines.ctest -E "^agc_driver|^video_out|^guest_video"): 615 of 616 pass, includingagc_performance_traceandprx_thread_local_destructors;log_macrosfails as onmainon that machine. TheBUILD_TESTINGbuild also linksagc_driver_mesh_testsand the other targets that compile the driver sources.APS5_TRACE_FRAMES=120:120wrote a 2.5 MB trace (26.6 MB of JSON, 284,124 events onqueue worker 0x0,queue worker 0x20andpresenter, nothing dropped) and its summary line. Perfetto's trace processor v58.2 (the engine of ui.perfetto.dev) imports it with no errors. Details are in a comment below. The first capture wrote nothing, because the bundled zlib has no gzip wrapper; the second commit fixes that.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T15:13:44Z.
Capture from a title run: Sword of the Sea (PPSA25344), main menu, RTX 5070 Laptop (NVIDIA 616.92), Windows 11 26200. The build is this PR's two commits on our lab branch, which carries the local patches the title still needs (cf01fcab4 in the summary).
APS5_TRACE_FRAMES=120:120: the window opened at present 120 and closed at present 240, 15.8 s later.aps5-trace-<commit>-<pid>.json.gz, 2.5 MB (26.6 MB of JSON).queue worker 0x0250,882,queue worker 0x2031,110,presenter1,651. Also 120presentinstants, 357<thread> foldedcounter samples (119 per thread, one per present) and 4 metadata events. No buffer filled, sotrace_droppedis false. Slices nest up to 7 deep, and no two slices on one thread overlap partially.trace_processor_shellv58.2, the engine behind ui.perfetto.dev) imports the file with no error in itsstats: 283,763 slices including the instants, three thread tracks, and the three counter tracks. A script also checked the JSON: every event hasname,ph,ts,pidandtid, and everyXevent hasdur≥ 0.The summary line (
APS5_TRACE_DIRis a path, so it is written as<path>):top_phases_ms_per_frameadds up all traced threads, soDriver.Packet(both queue workers) is longer than a frame.The first capture wrote no file, which is what the second commit fixes. The zlib in the tree (libjpeg-turbo's) is built with
NO_GZIP, sodeflateInit2refused the gzip wrapper. The error line was also lost, because the title's stderr is buffered. The trace now writes the gzip header and the CRC-32 and size trailer around a raw deflate stream and flushes its result line, and a test inflates a written file.The trace itself is not attached because it comes from a title run.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T17:50:45Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/include/PerformanceTimer.hppL3, L276-277, L300-301Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T18:16:52Z.
Read through dafae932. The code is fine by reading: malformed values throw at the first present, nothing falls back, and with the variables unset the cost is one relaxed atomic load per
PerformanceTimerand a null check inFinish/Mark, no allocation and nothing per draw.What it brings in is the part that needs a decision, and it is the owner's rather than mine:
APS5_TRACE_FRAMES,APS5_TRACE_SECONDSandAPS5_TRACE_DIR;jpeg_turbolinked intolibSceAgcDriver(and three test targets) to reach its bundled zlib, with the gzip framing written by hand because that zlib is built withNO_GZIP;git rev-parseandgit status --porcelainon every build, so the driver relinks whenever HEAD or the dirty flag changes;aps5-summary.jsonl, which lists everyAPS5_*variable of the run;PerformanceTimer.hpp.#4477 has no answer from him yet, so I am leaving this open until it does.
Two things in the meantime:
VulkanDevice.cpplost a space inauto byteFeatures =QueryBdaByteFeatures(; please drop that hunk.#4570 has no new variable or dependency, so it can go in on its own once its build is green. It conflicts with this one in
CMakeLists.txtanddocs/dev/BUILD.md, so this one will need a rebase after it.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T18:19:35Z.
@oneandonlydean thanks for the read. The
VulkanDevice.cppspace is fixed in a2c49da2d; that line is now identical tomain, so the hunk only adds the driver name.Agreed on the order: #4570 first, then I merge
maininto this one. #4632 (GPU track) and #4590 (perf template) build on it and will follow it.If it makes the owner's call easier, I can shrink what this brings in:
jpeg_turbolink and write plain.json(about 10x larger, but no compression dependency);commitfrom an existing build version string instead of thegit rev-parsestep, or leave it out;aps5-summary.jsonlto an allow-list of variables.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T18:38:43Z.
Update: this goes in as step 1 of #4477 once the Linux job of the build above is green, the
byteFeatures =hunk is dropped and it is rebased over #4570.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T19:19:19Z.
Reviewed a2c49da2d on Linux (GCC 16.2, Release):
libSceAgcDriverbuilds;agc_performance_trace,agc_profile_outputandagc_driver_meshpass.TraceFile::WriteGzipagainst the bundled zlib withNO_GZIP(and an empty one) passesgzip -t, and Python'sgzipreturns the same bytes.jpeg_turbolink reuses the zlib thatlibSceZlibalready links, so nothing new is vendored; the revision step is needed because the tree has no version string yet, andcopy_if_differentonly relinks when HEAD or the dirty flag changes;envis limited toAPS5_*and masks paths. Fine with all three as they are.<thread> foldedsample is written on the thread's first slice after a present, so the last present of the window gets none (119 samples for 120 presents in your capture). Its time is still in the totals and the summary; a line in BUILD.md or a flush at close would make the counter match "one per present".Ready from my side once it is rebased over #4570, as Dean said.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T19:43:21Z.
#4570 is merged. I rebased this on top of it: the conflicts in libSceAgcDriver's
CMakeLists.txtanddocs/dev/BUILD.mdkeep both sides (agc_stack_walknext toagc_performance_trace, and "Worker sampler" followed by "Performance trace"). I also added6116fc75e, one sentence in BUILD.md about the nit above: the last present of a window has no<thread> foldedsample.Linux (GCC 16.2), full build:
agc_performance_trace,agc_stack_walk,agc_profile_output,agc_driver_meshand the unwind/exception tests all pass (12/12). Running the full build workflow now, and I'll merge once it's green.Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-12T22:09:17Z.
@AlxcBTW I'd rather the profiler just runs in the background all the time so I can have a game running for a prolonged period, gather data and iterate from there.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T22:10:41Z.
@TideOPL makes sense. A long session is where the interesting stalls show up. The window is bounded today because every slice is buffered (262,144 events per thread). I'd add two modes in a follow-up PR:
APS5_TRACE_SUMMARY_EVERY=<seconds>: no per-event buffer, only the folded per-scope totals. Every N seconds it appends one line toaps5-summary.jsonl(frame p50/p90/p99, GPU busy, worker busy %, top phases for that interval). It's cheap enough to leave on for hours, andtrace_digest.pywould plot the lines over time.APS5_TRACE_EVERY=<period>:<length>[:<keep>]: repeats the full Chrome-trace window, e.g. 10 s every 5 min, and keeps the last<keep>trace files. That way, when something goes wrong 40 minutes in, a recent full trace is on disk.Would that cover what you want, or do you need a full trace of the whole session? That would need a streaming writer instead of the in-memory buffer.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by TideOPL on 2026-10-12T22:12:35Z.
@AlxcBTW, these are good. I would say a third option for streaming is ideal, looking long term when games stay up for longer than 1 - 2 hours, long traces could be great.
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T22:15:56Z.
@TideOPL agreed. I'll do it in three small PRs, in this order:
APS5_TRACE_SUMMARY_EVERY: interval summary lines, cheap enough to leave on. It's in progress.APS5_TRACE_EVERY: repeated full windows with rotation.I'll tag you on each.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T22:41:24Z.
@TideOPL step 1 is up: #4812 (
APS5_TRACE_SUMMARY_EVERY=<seconds>). It writes one summary line per interval, has no event buffer and can stay on for hours.trace_digest.py aps5-summary.jsonlprints a row per interval with p99/GPU sparklines. Repeated windows and streaming follow as their own PRs.AI-assisted: yes (Claude Code)