Commit Graph

4 Commits

Author SHA1 Message Date
6a321e5db4 tools: d3d12_switches and d3d12_run_fps set errors=replace on stdout
tests/test_tool_stdout_encoding.py asks it of every tool. d3d12_run_fps.py came
in with #2594 without it, which left that test red on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:23:47 +01:00
befe3aa137 d3d12_run_fps: an error of argparse's own is rewritten from fixed texts (TOOLS-D3D12-RUN-FPS)
From the review of 016554bef: `--json=<text>` and `--help=<text>` still came
back in the error ("ignored explicit argument '<text>'"). argparse raises
that for a known flag before parse_known_args returns, so counting unknown
arguments could not catch it.

The parser is now a subclass whose error() rewrites every message argparse
raises from a short list of fixed texts, with the option's own name where it
names one: "takes no value", "needs a value", the three texts of the tool's
own argument types, "a log is needed", and "not understood" for anything the
list does not know (another Python's wording, a check argparse gains later).
The tool's own errors go through fail(), unchanged. Nothing typed can reach
an error message by any path.

Test: python -I tests/test_d3d12_run_fps.py (22 tests). New: argparse's own
errors for --json=<marker>, --help=<marker>, bad --edges and --min-samples
values, an unknown flag and a missing log, with plain, quoted and spaced
markers; a message the list does not know; the fixed texts are the argument
types' own.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-29 02:25:07 +00:00
016554bef3 d3d12_run_fps: no argument comes back in an error, frame lines only where the logger wrote them, an unfinished last line skipped (TOOLS-D3D12-RUN-FPS)
From the review of 9f7587e19:

- An argument error named what was typed: a second log given without
  --compare came back as "unrecognized arguments: <path>", and a bad
  --min-samples value was quoted. Unknown arguments are now counted, not
  quoted, --min-samples has its own type whose message is fixed text, and
  options cannot be abbreviated.
- A frame line counts only at the start of a line or after the time stamp,
  level and target of the host's INFO message (leonida_gpu::host, and
  victory_gpu::host of the forks this runtime came from). The same words
  inside another message are not read.
- A last line the writer did not finish (no line end) is skipped whatever it
  holds, and the pattern asks for the words that follow the draw count, so a
  line cut after the count gives no sample.
- The text gives the textures' MB and the copy-back's MB too, as the JSON
  does.

Test: python -I tests/test_d3d12_run_fps.py (19 tests). New: a frame line
counts only where the logger wrote it; a last line without its end; no error
gives back what was typed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-29 01:15:08 +00:00
9f7587e193 tools: frame rate of a D3D12-runtime run by draws a frame, and two runs side by side (TOOLS-D3D12-RUN-FPS)
tools/d3d12_run_fps.py reads the frame line the D3D12 runtime logs every few
seconds (fps, ms a frame, preparing, copies, waiting on the GPU, copying back,
draws a frame) and prints numbers only: the samples in the world (the first
bucket's lower bound, 1000 draws a frame by default, leaves out menus and
loading screens), the frame rate (median, slowest tenth, fastest tenth), the
medians of where a frame goes, and the median frame rate per bucket of draws
a frame. --compare puts a second run beside the first bucket by bucket and
gives the change only where both runs have enough samples.

Why: two runs of the game never show the same scenes for the same time, so
their plain medians do not compare. Measured here on two real runs of one
save (numbers only): plain medians 15.6 and 16.2 fps, but by bucket the second
was 51%, 29%, 5% and 21% faster at 3-5k, 5-7k, 7-9k and 9k+ draws a frame: it
had spent its time in busier scenes (median 7,676 draws against 5,132).

It never prints a log line, a program name, an address or the path of a log;
the log stays on the machine that made it. Standard library only. Reads UTF-8
and UTF-16 logs (a PowerShell redirection writes UTF-16) and strips terminal
colour codes; a truncated last line is skipped. The pattern takes only what
the runtime's format string writes (bounded lengths, nothing in front of the
first number), so no other text in a log reads as a frame line.

Test: python -I tests/test_d3d12_run_fps.py (16 tests on synthetic lines in
the shape of the runtime's format string; no game files, no GPU). On main it
fails at import: the tool does not exist there.

Checked: python -I tests/test_d3d12_run_fps.py; python -I
tests/test_text_write_line_endings.py; python -I scripts/check_no_game_data.py
on the three files; eight deliberate breakages of the tool each fail a test.
A second, fresh session reviewed the first version; its findings are fixed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-28 22:50:37 +00:00