feat(tools): digest a performance trace for an issue or a pull request #4581

Merged
AlxcBTW merged 1 commit from upstream-pr/4581 into main 2026-10-12 20:13:37 +00:00
AlxcBTW commented 2026-10-12 16:09:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T16:09:35Z.


Step 2b of #4477. tools/trace_digest.py turns a trace from #4526 (and optionally a collapsed-stack file from #4570) into a markdown report of a few KB to paste into an issue, a pull request or a chat with an AI. --json prints the same data as JSON.

What

python3 tools/trace_digest.py aps5-trace-<commit>-<pid>.json.gz [--stacks worker.collapsed.txt] [--frames 5] [--top 10] [--json]

  • Summary: the line from aps5-summary.jsonl next to the trace whose trace field names this file (--summary takes another file), as a short header and as the raw JSON line.
  • Slowest frames: the --frames longest intervals between presents. For each: the present, its length, when it started, and the four largest slices inside it (inclusive time clipped to the frame, with their thread).
  • Threads, in ms per frame: busy (top-level slices minus waits), wait (the outermost slices whose last name part contains wait: Driver.WorkerWait, Driver.Packet.memory_wait, Driver.Present.inflight_wait, ...), untraced (no top-level slice, which includes the time in slices under 20 us), the thread's folded counter, and its two largest top-level slices.
  • Largest slices per frame, by name over all threads (inclusive), and the longest waits, each with its thread, time and present.
  • Worker stacks (--stacks): sample count, share of truncated walks, and the top self (leaf) and total frames. The frames that every complete stack shares (the thread's entry path) are left out of total.

Python standard library only, like the other tools. The trace and the summary are read as #4526 writes them, but the tool does not depend on that pull request to build or test.

Tested

  • trace_digest (new, tools/tests/test_trace_digest.py, registered with the other tool tests): a synthetic trace of two threads and three presents, a summary file with two lines, and a collapsed file. It checks that the right summary line is picked, that the frames end at the window, the slowest frame and its clipped slices, the busy, wait, untraced and folded split of both threads, the largest slices, the longest waits with their present, self and total stacks without the shared frames, and the command line (markdown under 5 KB with every section, and --json). It passes with Python 3.14 on Windows 11 and Python 3.12 on Ubuntu 24.04 (WSL).

  • The capture of #4526 (Sword of the Sea menu, 120 presents, 284,124 events) with the stacks of #4570: 2.1 s and 4.6 KB of markdown. For example, the thread table:

    thread busy wait untraced in slices < 20 us largest
    queue worker 0x0 117.9 (89 %) 8.7 (7 %) 5.4 22.5 Driver.Packet 125.5, Driver.Suspend 1.0
    presenter 0.9 (1 %) 1.8 (1 %) 129.3 0.1 Driver.Present 2.7
    queue worker 0x20 34.6 (26 %) 96.4 (73 %) 1.0 2.6 Driver.Packet 103.0, Driver.EndSubmission 1.1

    The ten longest waits are all Driver.Packet.memory_wait on queue worker 0x20, 43 to 48 ms each.

  • Conventions: tools/check_conventions.py --base origin/main passes.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4832013755 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4581). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T16:09:35Z. --- Step 2b of #4477. `tools/trace_digest.py` turns a trace from #4526 (and optionally a collapsed-stack file from #4570) into a markdown report of a few KB to paste into an issue, a pull request or a chat with an AI. `--json` prints the same data as JSON. ### What `python3 tools/trace_digest.py aps5-trace-<commit>-<pid>.json.gz [--stacks worker.collapsed.txt] [--frames 5] [--top 10] [--json]` - **Summary:** the line from `aps5-summary.jsonl` next to the trace whose `trace` field names this file (`--summary` takes another file), as a short header and as the raw JSON line. - **Slowest frames:** the `--frames` longest intervals between presents. For each: the present, its length, when it started, and the four largest slices inside it (inclusive time clipped to the frame, with their thread). - **Threads**, in ms per frame: busy (top-level slices minus waits), wait (the outermost slices whose last name part contains `wait`: `Driver.WorkerWait`, `Driver.Packet.memory_wait`, `Driver.Present.inflight_wait`, ...), untraced (no top-level slice, which includes the time in slices under 20 us), the thread's `folded` counter, and its two largest top-level slices. - **Largest slices** per frame, by name over all threads (inclusive), and the **longest waits**, each with its thread, time and present. - **Worker stacks** (`--stacks`): sample count, share of truncated walks, and the top `self` (leaf) and `total` frames. The frames that every complete stack shares (the thread's entry path) are left out of `total`. Python standard library only, like the other tools. The trace and the summary are read as #4526 writes them, but the tool does not depend on that pull request to build or test. ### Tested - **`trace_digest` (new, `tools/tests/test_trace_digest.py`, registered with the other tool tests):** a synthetic trace of two threads and three presents, a summary file with two lines, and a collapsed file. It checks that the right summary line is picked, that the frames end at the window, the slowest frame and its clipped slices, the busy, wait, untraced and folded split of both threads, the largest slices, the longest waits with their present, self and total stacks without the shared frames, and the command line (markdown under 5 KB with every section, and `--json`). It passes with Python 3.14 on Windows 11 and Python 3.12 on Ubuntu 24.04 (WSL). - **The capture of #4526** (Sword of the Sea menu, 120 presents, 284,124 events) with the stacks of #4570: 2.1 s and 4.6 KB of markdown. For example, the thread table: | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | queue worker 0x0 | 117.9 (89 %) | 8.7 (7 %) | 5.4 | 22.5 | Driver.Packet 125.5, Driver.Suspend 1.0 | | presenter | 0.9 (1 %) | 1.8 (1 %) | 129.3 | 0.1 | Driver.Present 2.7 | | queue worker 0x20 | 34.6 (26 %) | 96.4 (73 %) | 1.0 | 2.6 | Driver.Packet 103.0, Driver.EndSubmission 1.1 | The ten longest waits are all `Driver.Packet.memory_wait` on queue worker 0x20, 43 to 48 ms each. - **Conventions:** `tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-12 19:33:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T19:33:40Z.


Rebased on main: the only conflict was the root CMakeLists.txt, where pad_input landed next to trace_digest; both registrations are kept. test_trace_digest.py passes (8/8).

End to end check: I wrote a 6-present window with #4526's TraceFormat::Events/Summary and TraceFile::WriteGzip (compiled against the bundled zlib) and fed it to the script. Its summary line matches the C++ one field for field (frame p50/p90/p99, GPU busy per present, worker busy, top phases), and the slow frame and the waits land on the right presents.

I'll merge this right after #4526, following the order in #4477.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131238570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4581#issuecomment-6131238570). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T19:33:40Z. --- Rebased on main: the only conflict was the root `CMakeLists.txt`, where `pad_input` landed next to `trace_digest`; both registrations are kept. `test_trace_digest.py` passes (8/8). End to end check: I wrote a 6-present window with #4526's `TraceFormat::Events`/`Summary` and `TraceFile::WriteGzip` (compiled against the bundled zlib) and fed it to the script. Its summary line matches the C++ one field for field (frame p50/p90/p99, GPU busy per present, worker busy, top phases), and the slow frame and the waits land on the right presents. I'll merge this right after #4526, following the order in #4477.
github-actions[bot] commented 2026-10-12 20:09:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:09:34Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4730 CMakeLists.txt L101
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131784297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4581#issuecomment-6131784297). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T20:09:34Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4730 | `CMakeLists.txt` [L101](https://github.com/boykopovar/AnyPS5/blob/01422156878b455efc0bbfaa33cd5b0cd28c2587/CMakeLists.txt#L101) | | |
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!4581
No description provided.