runtime: write opt-in time lines to the stand-in log (X2W_LOG_TIME) #3563

Manually merged
github merged 3 commits from github-bot/gh-3561 into gh-pr/3561/base 2026-11-30 17:30:26 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-30 06:58 UTC · original
Leyukaka:arch-review-log-time → main · +143 −1 · 6 files · 3 commits · merged 2026-11-30 17:26 UTC

Change

Most stand-in log lines carry no time. After a start-up run, such a line in stderr.txt cannot be
placed against the launcher's events.txt, which is timed, except by interpolating between the
few lines that print a time.

X2W_LOG_TIME=1 (opt-in, read once per module) makes the stand-ins write

x2w-time 12.345 s

before a log line when the same module wrote no such line in the last 100 ms. The value is
x2w_local::process_seconds() (seconds since the process was created), printed with three
decimals. It goes to stderr and X2W_TRAP_LOG like any other line.

  • Every existing line stays byte for byte the same; no prefix is added to a line, because
    triage_run.py (fullmatch) and live_view.py (startswith) match lines from their first
    character.
  • Unset, or set to anything not starting with 1, nothing is written; the cost is one cached
    test per log line.
  • Call sites: x2w_local::logf, and the two local log functions in
    src/startup_stubs/d3d12_xs_device.cpp and src/startup_stubs/xcrdapi.cpp (one line each).
  • Each stand-in DLL keeps its own 100 ms window. x2w-trap lines (x2w_trap::record) and
    x2w-teardown lines (d3d12_teardown.h) get none.
  • The caller's GetLastError value is kept.

This is an independent diagnostic change. No shared interface changes; no existing log line,
manifest or cache key changes.

Verification

Base: main at 2ff74a6ac. Head: a7078e3f9. Windows, MSVC 19.44, clean dev build.

cmake --preset dev
cmake --build --preset dev --target startup_local_log_check d3d12_xs_shim startup_stub_xcrdapi
ctest --preset dev --no-tests=error -R '^startup_local_log_time' -V

Result on a7078e3f9: build exit 0 (d3d12_xs.dll and XCRDAPI.dll link);
startup_local_log_time Passed, startup_local_log_time_control Passed, 2/2. The control runs
the same phase with X2W_LOG_TIME=0 and passes only on the output line
FAIL the first logged line follows an x2w-time line (PASS_REGULAR_EXPRESSION).

The test redirects stderr to a file and checks: the first line is an x2w-time line; each one
reads x2w-time <seconds> s with exactly three decimals; the seconds never go back; the 52
logged lines are present and unchanged; stderr and X2W_TRAP_LOG hold the same bytes; a burst of
50 lines shares x2w-time lines; a line logged 250 ms later follows a new one at least 0.2 s
later; GetLastError is kept.

Existing tests, on the first commit 73f7292cf (the second commit changes only a comment in
local_log.h, the test and its registration):

ctest --preset dev --no-tests=error -R '^startup_local_log'

Result: 8 Passed, 1 Not Run. startup_local_log_cache_failure_control did not run because its
target startup_local_log_cache_failure_check was not in the build list above; it was not
checked. The existing tests were not run again on a7078e3f9.

Mutations, each built and run with the first commands:

  • logf without its time_anchor(); call: startup_local_log_time fails
    (the first logged line follows an x2w-time line).
  • now >= due && -> true && (no 100 ms limit): startup_local_log_time fails
    (x2w-time lines are limited to one per 100 ms).
  • time_anchor without its stderr write: startup_local_log_time fails
    (stderr carries the same lines).
  • the phase returns 2 early when X2W_LOG_TIME is off: startup_local_log_time_control fails
    (required FAIL line not found).

Not covered: the one-line call sites in d3d12_xs_device.cpp and xcrdapi.cpp (the test drives
logf only; they are built, not run), the per-module window when several stand-ins log at once,
logging from several threads, and triage_run.py / live_view.py on a log that contains
x2w-time lines.

Evidence and follow-up

The new test phase (startup_local_log_check --phase log-time) uses only synthetic lines
written by the test itself; no fixture file is added. Its CTest registration is in a new
fragment, tests/cmake/startup_local_log_time.cmake, so CMakeLists.txt is not edited.

Assumptions:

  • process_seconds() uses the system clock (GetSystemTimeAsFileTime), so its resolution is the
    system timer tick and a clock change during a run moves the values.
  • A line is at most about 100 ms (plus one GetTickCount64 step) later than the x2w-time line
    before it only for lines from one thread. Across threads the exchange can race, and stderr and
    X2W_TRAP_LOG can order lines differently.

Documentation: one row for X2W_LOG_TIME=1 in the switch table of docs/startup-runtime.md,
with the reproduction command.

Possible follow-up for anyone: the three copies of the line writer (local_log.h,
d3d12_xs_device.cpp, xcrdapi.cpp) could become one.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include application files, dumps, distribution links or secrets.
**@⁠Leyukaka** on GitHub · 2026-11-30 06:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3561) `Leyukaka:arch-review-log-time` → `main` · +143 −1 · 6 files · 3 commits · merged 2026-11-30 17:26 UTC ## Change Most stand-in log lines carry no time. After a start-up run, such a line in `stderr.txt` cannot be placed against the launcher's `events.txt`, which is timed, except by interpolating between the few lines that print a time. `X2W_LOG_TIME=1` (opt-in, read once per module) makes the stand-ins write ```text x2w-time 12.345 s ``` before a log line when the same module wrote no such line in the last 100 ms. The value is `x2w_local::process_seconds()` (seconds since the process was created), printed with three decimals. It goes to stderr and `X2W_TRAP_LOG` like any other line. - Every existing line stays byte for byte the same; no prefix is added to a line, because `triage_run.py` (`fullmatch`) and `live_view.py` (`startswith`) match lines from their first character. - Unset, or set to anything not starting with `1`, nothing is written; the cost is one cached test per log line. - Call sites: `x2w_local::logf`, and the two local `log` functions in `src/startup_stubs/d3d12_xs_device.cpp` and `src/startup_stubs/xcrdapi.cpp` (one line each). - Each stand-in DLL keeps its own 100 ms window. `x2w-trap` lines (`x2w_trap::record`) and `x2w-teardown` lines (`d3d12_teardown.h`) get none. - The caller's `GetLastError` value is kept. This is an independent diagnostic change. No shared interface changes; no existing log line, manifest or cache key changes. ## Verification Base: `main` at `2ff74a6ac`. Head: `a7078e3f9`. Windows, MSVC 19.44, clean `dev` build. ```powershell cmake --preset dev cmake --build --preset dev --target startup_local_log_check d3d12_xs_shim startup_stub_xcrdapi ctest --preset dev --no-tests=error -R '^startup_local_log_time' -V ``` Result on `a7078e3f9`: build exit 0 (`d3d12_xs.dll` and `XCRDAPI.dll` link); `startup_local_log_time` Passed, `startup_local_log_time_control` Passed, 2/2. The control runs the same phase with `X2W_LOG_TIME=0` and passes only on the output line `FAIL the first logged line follows an x2w-time line` (`PASS_REGULAR_EXPRESSION`). The test redirects stderr to a file and checks: the first line is an `x2w-time` line; each one reads `x2w-time <seconds> s` with exactly three decimals; the seconds never go back; the 52 logged lines are present and unchanged; stderr and `X2W_TRAP_LOG` hold the same bytes; a burst of 50 lines shares `x2w-time` lines; a line logged 250 ms later follows a new one at least 0.2 s later; `GetLastError` is kept. Existing tests, on the first commit `73f7292cf` (the second commit changes only a comment in `local_log.h`, the test and its registration): ```powershell ctest --preset dev --no-tests=error -R '^startup_local_log' ``` Result: 8 Passed, 1 Not Run. `startup_local_log_cache_failure_control` did not run because its target `startup_local_log_cache_failure_check` was not in the build list above; it was not checked. The existing tests were not run again on `a7078e3f9`. Mutations, each built and run with the first commands: - `logf` without its `time_anchor();` call: `startup_local_log_time` fails (`the first logged line follows an x2w-time line`). - `now >= due &&` -> `true &&` (no 100 ms limit): `startup_local_log_time` fails (`x2w-time lines are limited to one per 100 ms`). - `time_anchor` without its stderr write: `startup_local_log_time` fails (`stderr carries the same lines`). - the phase returns 2 early when `X2W_LOG_TIME` is off: `startup_local_log_time_control` fails (required FAIL line not found). Not covered: the one-line call sites in `d3d12_xs_device.cpp` and `xcrdapi.cpp` (the test drives `logf` only; they are built, not run), the per-module window when several stand-ins log at once, logging from several threads, and `triage_run.py` / `live_view.py` on a log that contains `x2w-time` lines. ## Evidence and follow-up The new test phase (`startup_local_log_check --phase log-time`) uses only synthetic lines written by the test itself; no fixture file is added. Its CTest registration is in a new fragment, `tests/cmake/startup_local_log_time.cmake`, so `CMakeLists.txt` is not edited. Assumptions: - `process_seconds()` uses the system clock (`GetSystemTimeAsFileTime`), so its resolution is the system timer tick and a clock change during a run moves the values. - A line is at most about 100 ms (plus one `GetTickCount64` step) later than the `x2w-time` line before it only for lines from one thread. Across threads the exchange can race, and stderr and `X2W_TRAP_LOG` can order lines differently. Documentation: one row for `X2W_LOG_TIME=1` in the switch table of `docs/startup-runtime.md`, with the reproduction command. Possible follow-up for anyone: the three copies of the line writer (`local_log.h`, `d3d12_xs_device.cpp`, `xcrdapi.cpp`) could become one. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include application files, dumps, distribution links or secrets.
Stand-in log lines carry no time, so a line in stderr.txt cannot be
placed against the launcher's events.txt.

With X2W_LOG_TIME=1, logf and the log functions of d3d12_xs and xcrdapi
write "x2w-time <seconds> s" (seconds since the process was created)
before a line when the same module wrote no such line in the last
100 ms. Every other line is unchanged, so tools that match whole lines
keep working. Unset, nothing is added.

startup_local_log_time checks the lines through logf;
startup_local_log_time_control runs the same phase with the switch off
and must fail.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 07:00:20 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 09:07 UTC · original · approved these changes

Reviewed a7078e3f by reading the diff; not built or run.

Verdict: approve. Opt-in, off by default, and every existing line stays byte for byte the same. No MUST.

  • Coverage: the three call sites are all the Win32 stderr writers in the stand-ins, apart from x2w_trap::record (trap.h:153), which is excluded on purpose. The only other stderr output is the std::fprintf lines of the opt-in x2w-cache-probe trace (d3d12_xs_device.cpp:7011-7081), which get no x2w-time line. That is worth one clause in the doc row, since it says "the stand-ins write".
  • Per module: time_anchor is an inline function in a header, so its static next is one object per DLL across translation units, which gives the per-module window the doc describes. GetLastError is saved and restored around the anchor in logf and in both local log functions.
  • Concurrency: the compare-exchange on next lets exactly one thread write an anchor per window, and a losing thread just logs its line. That matches the documented "across threads the order can differ".
  • Tools: neither triage_run.py nor live_view.py reads the last line or a neighbouring line, so an extra x2w-time line is just one more unmatched line for them.
  • CI: the red Linux job is startup_triage_run_check.py failing on "an output UAV interval exceeds the D3D12 buffer view element limit" missing from COMPUTE_DISPATCH_REASONS. That is main's failure (#3509), not this change.

Tests: startup_local_log_time checks the first anchor, the three-decimal format, monotonic seconds, unchanged lines, identical stderr and X2W_TRAP_LOG bytes, the 100 ms limit and GetLastError. The X2W_LOG_TIME=0 control and the four mutations show each check can fail. CI did not run them: they are not in the pr preset's list.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 09:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3561#pullrequestreview-6109362216) · **approved these changes** Reviewed `a7078e3f` by reading the diff; not built or run. **Verdict: approve.** Opt-in, off by default, and every existing line stays byte for byte the same. No MUST. - Coverage: the three call sites are all the Win32 stderr writers in the stand-ins, apart from `x2w_trap::record` (`trap.h:153`), which is excluded on purpose. The only other stderr output is the `std::fprintf` lines of the opt-in `x2w-cache-probe` trace (`d3d12_xs_device.cpp:7011`-`7081`), which get no `x2w-time` line. That is worth one clause in the doc row, since it says "the stand-ins write". - Per module: `time_anchor` is an inline function in a header, so its `static next` is one object per DLL across translation units, which gives the per-module window the doc describes. `GetLastError` is saved and restored around the anchor in `logf` and in both local `log` functions. - Concurrency: the compare-exchange on `next` lets exactly one thread write an anchor per window, and a losing thread just logs its line. That matches the documented "across threads the order can differ". - Tools: neither `triage_run.py` nor `live_view.py` reads the last line or a neighbouring line, so an extra `x2w-time` line is just one more unmatched line for them. - CI: the red Linux job is `startup_triage_run_check.py` failing on "an output UAV interval exceeds the D3D12 buffer view element limit" missing from `COMPUTE_DISPATCH_REASONS`. That is main's failure (#3509), not this change. Tests: `startup_local_log_time` checks the first anchor, the three-decimal format, monotonic seconds, unchanged lines, identical stderr and `X2W_TRAP_LOG` bytes, the 100 ms limit and `GetLastError`. The `X2W_LOG_TIME=0` control and the four mutations show each check can fail. CI did not run them: they are not in the `pr` preset's list.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-30 17:22 UTC · original · approved these changes

Reviewed the main-updated head. The added timestamp calls are opt-in and preserve the normal logging routes and GetLastError. Built the exact-head tests/startup_local_log_check.cpp with cl.exe /nologo /EHsc /std:c++17 /Isrc on Windows. X2W_LOG_TIME=1 with --phase log-time passed all 10 checks, X2W_LOG_TIME=0 hit the expected first-anchor assertion, and the normal fixture passed 104 cases. Waiting for hosted checks on this head.

**@⁠R0Y00** on GitHub · 2026-11-30 17:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3561#pullrequestreview-6117033034) · **approved these changes** Reviewed the main-updated head. The added timestamp calls are opt-in and preserve the normal logging routes and GetLastError. Built the exact-head `tests/startup_local_log_check.cpp` with `cl.exe /nologo /EHsc /std:c++17 /Isrc` on Windows. `X2W_LOG_TIME=1` with `--phase log-time` passed all 10 checks, `X2W_LOG_TIME=0` hit the expected first-anchor assertion, and the normal fixture passed 104 cases. Waiting for hosted checks on this head.
github-bot changed target branch from main to gh-pr/3561/base 2026-11-30 17:30:25 +00:00
github manually merged commit 7eca1f8afd into gh-pr/3561/base 2026-11-30 17:30:26 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.