tools: log thread ids and per-thread gaps in traced calls #3499

Open
Leyukaka wants to merge 2 commits from upstream-pr/3499 into main
Leyukaka commented 2026-11-29 18:19:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T18:19:52Z.


Refs #3477 (item 8, https://github.com/R0Y00/Xbox2Windows/issues/3477#issuecomment-7260217772).

Stacked on #3463: until it merges, this PR also shows its commit. The change here is the last two commits, 23fa52f8 and 9699aa4f (head).

Why

In a long local run of the application, the trace could not say which thread stopped issuing work before the stop.

What changes

  • tools/startup/debug_launch.py: return lines of runtime and movie-player calls (--trace-calls) in files.txt end with tid=<id> gap_ms=<ms|n/a>. File-hook lines (NtCreateFile, NtOpenFile, ...) keep their format.

    <seconds> <call> -> 0x00000001 tid=<id> gap_ms=<ms|n/a>
    
  • tools/startup/hook_window.py: new trace_call_suffix. The gap is per thread, from time.monotonic(), between that thread's logged trace lines, in ms with 3 decimals. The first line of a thread has gap_ms=n/a.

  • Exception and debugger stop lines in events.txt end with tid=<id>.

  • tools/startup/triage_run.py, tools/startup/exit_report.py: the debugger stop regex accepts the optional tid= suffix, with the same captures. The exception regexes are not end-anchored and needed no change.

  • live_view.py and the other consumers of these lines are unaffected.

Tests

  • tests/startup_hook_check.py, tests/startup_triage_run_check.py, tests/startup_exit_report_check.py: pass.
  • cmake --preset dev -DX2W_WITH_OPUS:BOOL=OFF, build targets startup_debug_probe and startup_debug_calls, then ctest -R '^startup_debug(_log|_hooks)?$': 3/3 passed.

Mutations, each caught by a failing check:

Mutation Fails
one timestamp shared by all threads in trace_call_suffix startup_hook_check
tid= dropped from the exception line startup_debug
old stop regex in triage_run.py startup_triage_run_check
old stop regex in exit_report.py startup_exit_report_check
suffix dropped from the traced-call return line startup_debug_hooks
tid= dropped from the debugger stop line startup_debug
per-thread timestamp not cleared on thread exit startup_debug_hooks (a new thread reusing the exited thread's id gets a numeric gap instead of n/a)

docs/startup-runtime.md describes the tid and gap_ms fields.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5553680511 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3499). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T18:19:52Z. --- Refs #3477 (item 8, https://github.com/R0Y00/Xbox2Windows/issues/3477#issuecomment-7260217772). Stacked on #3463: until it merges, this PR also shows its commit. The change here is the last two commits, 23fa52f8 and 9699aa4f (head). ## Why In a long local run of the application, the trace could not say which thread stopped issuing work before the stop. ## What changes - `tools/startup/debug_launch.py`: return lines of runtime and movie-player calls (`--trace-calls`) in `files.txt` end with `tid=<id> gap_ms=<ms|n/a>`. File-hook lines (`NtCreateFile`, `NtOpenFile`, ...) keep their format. ``` <seconds> <call> -> 0x00000001 tid=<id> gap_ms=<ms|n/a> ``` - `tools/startup/hook_window.py`: new `trace_call_suffix`. The gap is per thread, from `time.monotonic()`, between that thread's logged trace lines, in ms with 3 decimals. The first line of a thread has `gap_ms=n/a`. - Exception and debugger stop lines in `events.txt` end with ` tid=<id>`. - `tools/startup/triage_run.py`, `tools/startup/exit_report.py`: the debugger stop regex accepts the optional `tid=` suffix, with the same captures. The exception regexes are not end-anchored and needed no change. - `live_view.py` and the other consumers of these lines are unaffected. ## Tests - `tests/startup_hook_check.py`, `tests/startup_triage_run_check.py`, `tests/startup_exit_report_check.py`: pass. - `cmake --preset dev -DX2W_WITH_OPUS:BOOL=OFF`, build targets `startup_debug_probe` and `startup_debug_calls`, then `ctest -R '^startup_debug(_log|_hooks)?$'`: 3/3 passed. Mutations, each caught by a failing check: | Mutation | Fails | |---|---| | one timestamp shared by all threads in `trace_call_suffix` | `startup_hook_check` | | ` tid=` dropped from the exception line | `startup_debug` | | old stop regex in `triage_run.py` | `startup_triage_run_check` | | old stop regex in `exit_report.py` | `startup_exit_report_check` | | suffix dropped from the traced-call return line | `startup_debug_hooks` | | ` tid=` dropped from the debugger stop line | `startup_debug` | | per-thread timestamp not cleared on thread exit | `startup_debug_hooks` (a new thread reusing the exited thread's id gets a numeric gap instead of `n/a`) | `docs/startup-runtime.md` describes the `tid` and `gap_ms` fields.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3499:upstream-pr/3499'
git switch 'upstream-pr/3499'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3499'
git switch 'upstream-pr/3499'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3499'
git switch 'upstream-pr/3499'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3499'
git switch 'main'
git merge --squash 'upstream-pr/3499'
git switch 'main'
git merge --ff-only 'upstream-pr/3499'
git switch 'main'
git merge 'upstream-pr/3499'
git push origin 'main'
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
R0Y00/Xbox2Windows!3499
No description provided.