feat(agc): write the worker sampler's stacks as collapsed stacks #4570
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4570"
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-12T15:53:29Z.
Step 2 of #4477. The worker sampler (
APS5_SAMPLE_WORKER) also writes the queue worker's whole stacks as collapsed stacks, which speedscope.app and flamegraph.pl open as a flame graph. Its walk now gets through the libraries' DWARF-only frames, so most stacks reach the thread's root. The perf template that asks for a trace and a flame graph is a follow-up.What
<file>, every 20 s and at exit, the sampler writes<file stem>.collapsed.txt: oneframe;...;frame countline per distinct stack of queue worker 0, root first, each frame asmodule+0xRVA. A walk that ends before the thread's root starts with[truncated].#lines hold the sample count, the walk depth, the truncated walks, the mean and longest time the worker was suspended, and each module's name, size and PE timestamp (no paths), so a file can be checked against the binary it is symbolized with. The file is replaced through a temporary file, so a reader never sees a partial one.<file>keeps its format.-fno-asynchronous-unwind-tables, so most of their functions have no.pdataentry, only a DWARF record in.ehfram.RtlLookupFunctionEntryfinds nothing there, and the walk ended at the first such frame. The worker's walk now steps such a frame through its record: CFA rule, return address and the saved registers. A leaf without either kind of record takes its return address fromrspif that address has unwind data..ehframis indexed after the worker resumes. Walks go up to 64 frames. The process sampler (APS5_SAMPLE_THREADS) keeps its 12 frames through.pdataonly.DecodeRange) and the call frame instruction interpreter (Instructions) are libc's, used by its_Unwind_*functions. They move unchanged fromUnwind.cppintoexceptions/Unwind.hppas inline functions. The sampler doesn't call libc'sStep, becauseStepindexes modules lazily under a mutex and reads saved registers anywhere in memory, and neither is allowed while the worker is suspended.StackWalk.hppholds the per-module FDE index, the step and the collapsed-stack formatting, and doesn't depend on Windows.docs/dev/BUILD.md(Worker sampler, which also listsAPS5_SAMPLE_THREADS).Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release.
agc_stack_walk(new): a synthetic.eh_frame(azRCIE with a pc-relative FDE for apush rbp; mov rbp, rspprologue) and a stack array. It steps at the function's entry, after the push, and in the body through the frame pointer. A pc outside the record gives no record, a read outside the stack is refused with the registers unchanged, and MinGW's return column 32 is read (Windows; elsewhere the CIE is not indexed). It also checks the collapsed-stack text: merged stacks, root first, and[truncated]. It passes on Windows and, built alone, on Linux with GCC 13.3.ctest -E "^agc_driver|^video_out|^guest_video"): 618 of 619 pass, includingagc_stack_walk,windows_exceptions,guest_exception_handler,guest_raise_exception,guest_unwind_module_info,unwind_record_boundsandprx_thread_local_destructors.log_macrosfails as onmainon that machine. libc'sUnwind.cpp,Personality.cppandExceptionPersonality.cppalso compile without warnings on Linux (GCC 13.3, syntax check).[truncated]). Depth is 18.8 frames on average and 48 at most. The worker was suspended 102 us per sample on average. Before this change, no walk on the same menu reached the root. Details are in a comment below.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-12T16:07:19Z.
Capture from a title run: Sword of the Sea (PPSA25344), main menu, RTX 5070 Laptop (NVIDIA 616.92), Windows 11 26200, 150 s. The build is this PR's commit on our lab branch (with #4526), which carries the local patches the title still needs. Our lab branch also had an older local version of this sampler, which was reverted for this build.
APS5_SAMPLE_WORKER=<dir>\worker.txt.worker.txt(136 KB, the existing format) andworker.collapsed.txt(1.5 MB): 8,966 samples in 3,319 distinct stacks, 14# modulelines with base names only. The lab stopped the title at the timeout, so these are from the last 20 s write.ntdll.dll, throughlibSceAgcDriver.prx,libstdc++-6.dll,ucrtbase.dllandKERNEL32.DLL), and 10 are[truncated]. Depth is 18.8 frames on average and 48 at most, so none hit the 64-frame cap. Before this change, the walk ended at the first frame that has only a DWARF record: in an earlier run of the same menu on our lab branch, no walk reached the root, and the largest inclusive count was 2,804 of 10,248 samples.suspended_us_mean). The longest suspension was 16.3 ms (suspended_us_max).#:frame;...;frame count, each framemodule+0x<hex>, with[truncated]only as the first frame. That is the line format speedscope's "collapsed stack" import andflamegraph.plread; both skip the#lines. The frames are unsymbolized RVAs, as inworker.txt.The sampler output itself is not attached because it comes from a title run.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T16:29:03Z.
Preparing a007 Windows diagnostic cross-test of7628167beb7d2b05f1c4300d157c03149b0f70b1. Applied cleanly on our current integration, source-only308d7a09d02380489422b5c6df7ff40527d846c7: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-worker-stacks-cross-test . Conventions pass. Will freshly build stack-walk plus relevant Windows unwind/exception tests before staging. Current game is still on older9e54939c9 graphics with sampling OFF; no runtime verification claim for4570 yet. The earlier copying hot samples lacked reliable callers, so DWARF walks should help distinguish costs. Profiles/title data stay local; public results will be aggregate native hot-path metadata. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T16:50:14Z.
Windows diagnostic preparation completed on head 4a4fc98be5e39198844a7dc2732764daa13d2f18: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-dispatch-provenance-cross-test . Carries credited #4570 (canonical 7628167b) on the #4586 integration, plus opt-in failure-only dispatch provenance. Original Vulkan argument address/CPU reason and failed indirect command argument address/initiator/queue/opcode are reported; validation unchanged.
Fresh focused checks: 8/8 passed in 17.50 s (stack walk, Windows exceptions, guest handler/raise/unwind module info, oversized GPU dispatch, indirect argument ordering, WRITE_DATA ordering), no skips. Final driver-trace follow-up: 3/3 GPU dispatch checks passed in 1.25 s. The oversized fixture emitted direct-input provenance and still rejected the invalid dimensions. Conventions pass. exception_runtime_tests is not an available target in this Windows configuration and is not included in the count.
Patched graphics SHA256 0044167482FC6932E575001A44E2E40B7557D4F8AA55270C13531918AB56AF82; patched libc 7540B4D811D1F1EB5C534A3DD29109319042B0DA592A0F15D114CF83F34D74F1. Preparing a sampled diagnostic007 repeat with 12 GiB import budget; not a quiet FPS comparison. Current title runs and raw profiles remain local; no runtime stack-walk result yet. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T19:06:04Z.
Conflicts with
mainincore/libs/prx/libc/src/exception/Unwind.cppsince #4511 went in: it changed the CIE/FDE decoding this PR moves into the header, so the moved code needs #4511's change applied by hand. Please rebase; the full build was green on 7628167b, and I'll rebuild and merge once the new head is up. #4526 goes in after it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T19:30:21Z.
Rebased onto
main(428963d3b). The only conflict was #4511's change toUnwind.cpp: its two newFramefields (foreign,caller, Windows only) now sit in the struct this PR moves intoexceptions/Unwind.hpp; the rest ofUnwind.cppkeeps #4511's code as onmain. Checked on Linux (GCC 16.2, Release): full build, and the unwind/exception tests pass withagc_stack_walk(13/13). Full Linux + Windows build dispatched for the new head.