tools: dump threads when a run stops presenting (X2W_DUMP_ON_STALL) #3676

Manually merged
github merged 1 commit from github-bot/gh-3674 into main 2026-12-01 01:19:26 +00:00 AGit
Owner

@⁠Jess-Doit on GitHub · 2026-11-30 23:59 UTC · original
Jess-Doit:startup/dump-on-stall → main · +167 −0 · 6 files · 1 commits · merged 2026-12-01 01:17 UTC

Refs #870.

Problem

X2W_DUMP_AT=<seconds> writes every thread's stack at fixed times. A stall that ends a run often starts at a time that changes from run to run, because it depends on how fast the load goes. On a GTX 1060 host, ten fixed dump times between 600 and 900 s all missed one: that run stopped presenting at about 1,006 s.

Change

  • New option. X2W_DUMP_ON_STALL=<seconds> makes the startup debugger (tools/startup/debug_launch.py) read trap.log about once a second, from the end of the previous read, and follow the stand-in's x2w-d3d12 heartbeat: <n> frames presented count.
  • When it dumps. Once the count has not changed for that long, it writes every thread's stack to threads_stall_<seconds into the run>.txt and logs no new frame for <s> s (last heartbeat <n> frames): threads dumped.
  • Further dumps. It dumps again after each further stall of the same length, at most three times. A new frame count starts the wait again, and nothing is dumped before the first heartbeat.
  • Unset. Nothing changes.
  • The decision is in tools/startup/stall_watch.py, a small module without Windows imports, so it can be checked anywhere.
  • Docs. docs/startup-runtime.md has a row next to X2W_DUMP_AT.

Tests

tests/startup_stall_watch_check.py is registered in tests/cmake/startup_stall_watch.cmake and in tests/checks/python-linux. It checks:

  • no dump before the first heartbeat;
  • 14 s versus 15 s without a new frame;
  • the next dump only after a further stall;
  • a new frame count restarting the wait;
  • the cap of three dumps;
  • the last heartbeat in a block of text being the one that counts;
  • a zero time being refused.

Two controls must fail:

  • --mutate no-reset keeps timing from the first heartbeat after frames move on. It fails 2 cases.
  • --mutate early dumps before the first heartbeat. It fails 1 case.
Command Result
python -B tests/startup_stall_watch_check.py all cases passed
... --mutate no-reset / ... --mutate early exit 1 (as required)
tests/startup_debug_launch_args_check.py (runs debug_launch.py, so the new import is loaded) 15 malformed option values rejected
tests/startup_tools_lint_check.py, tests/docs_links_check.py, tests/run_checks_parallel_check.py, git diff --check pass

Use on a package run

Before this was split into a module, the same logic ran in two package runs on a GTX 1060 6 GB (Windows 10 19045):

  • One dumped at 804 s and at 1,190 s. The second dump showed the title's render thread parked and its main thread waiting.
  • One with the shared presets dumped at 423, 439 and 454 s. Title worker threads were queued on a stand-in request lock while one thread wrote request files, which led to #3666.

🤖 Generated with Claude Code

**@⁠Jess-Doit** on GitHub · 2026-11-30 23:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3674) `Jess-Doit:startup/dump-on-stall` → `main` · +167 −0 · 6 files · 1 commits · merged 2026-12-01 01:17 UTC Refs #870. ## Problem `X2W_DUMP_AT=<seconds>` writes every thread's stack at fixed times. A stall that ends a run often starts at a time that changes from run to run, because it depends on how fast the load goes. On a GTX 1060 host, ten fixed dump times between 600 and 900 s all missed one: that run stopped presenting at about 1,006 s. ## Change - **New option.** `X2W_DUMP_ON_STALL=<seconds>` makes the startup debugger (`tools/startup/debug_launch.py`) read `trap.log` about once a second, from the end of the previous read, and follow the stand-in's `x2w-d3d12 heartbeat: <n> frames presented` count. - **When it dumps.** Once the count has not changed for that long, it writes every thread's stack to `threads_stall_<seconds into the run>.txt` and logs `no new frame for <s> s (last heartbeat <n> frames): threads dumped`. - **Further dumps.** It dumps again after each further stall of the same length, at most three times. A new frame count starts the wait again, and nothing is dumped before the first heartbeat. - **Unset.** Nothing changes. - **The decision** is in `tools/startup/stall_watch.py`, a small module without Windows imports, so it can be checked anywhere. - **Docs.** `docs/startup-runtime.md` has a row next to `X2W_DUMP_AT`. ## Tests `tests/startup_stall_watch_check.py` is registered in `tests/cmake/startup_stall_watch.cmake` and in `tests/checks/python-linux`. It checks: - no dump before the first heartbeat; - 14 s versus 15 s without a new frame; - the next dump only after a further stall; - a new frame count restarting the wait; - the cap of three dumps; - the last heartbeat in a block of text being the one that counts; - a zero time being refused. Two controls must fail: - `--mutate no-reset` keeps timing from the first heartbeat after frames move on. It fails 2 cases. - `--mutate early` dumps before the first heartbeat. It fails 1 case. | Command | Result | |---|---| | `python -B tests/startup_stall_watch_check.py` | all cases passed | | `... --mutate no-reset` / `... --mutate early` | exit 1 (as required) | | `tests/startup_debug_launch_args_check.py` (runs `debug_launch.py`, so the new import is loaded) | 15 malformed option values rejected | | `tests/startup_tools_lint_check.py`, `tests/docs_links_check.py`, `tests/run_checks_parallel_check.py`, `git diff --check` | pass | ## Use on a package run Before this was split into a module, the same logic ran in two package runs on a GTX 1060 6 GB (Windows 10 19045): - **One** dumped at 804 s and at 1,190 s. The second dump showed the title's render thread parked and its main thread waiting. - **One with the shared presets** dumped at 423, 439 and 454 s. Title worker threads were queued on a stand-in request lock while one thread wrote request files, which led to #3666. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
X2W_DUMP_AT needs the stall time in advance. X2W_DUMP_ON_STALL=<s> has
the startup debugger watch the stand-in's heartbeat frame count in
trap.log and write every thread's stack once it has not changed for
that long, at most three times. The decision is in stall_watch.py, with
a device-free check and two controls that must fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 00:00:40 +00:00
github manually merged commit a6cad06193 into main 2026-12-01 01:19:26 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-01 01:14 UTC · original · approved these changes

Reviewed the opt-in stall watcher. It waits for the first heartbeat, restarts the interval when the frame count changes, and caps dumps. ctest --test-dir <build> --no-tests=error -j1 -R '^startup_stall_watch' --output-on-failure passed all three cases, including the early-dump and no-reset controls.

**@⁠R0Y00** on GitHub · 2026-12-01 01:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3674#pullrequestreview-6123434120) · **approved these changes** Reviewed the opt-in stall watcher. It waits for the first heartbeat, restarts the interval when the frame count changes, and caps dumps. `ctest --test-dir <build> --no-tests=error -j1 -R '^startup_stall_watch' --output-on-failure` passed all three cases, including the early-dump and no-reset controls.
This discussion has been locked. Commenting is limited to contributors.
No description provided.