Skip to content

tools: frame rate of a D3D12-runtime run by draws a frame, and two runs side by side (TOOLS-D3D12-RUN-FPS) - #2594

Open
owenjbendon-creator wants to merge 3 commits into
ProjectLeonida:mainfrom
owenjbendon-creator:tools-d3d12-run-fps
Open

owenjbendon-creator wants to merge 3 commits into
ProjectLeonida:mainfrom
owenjbendon-creator:tools-d3d12-run-fps

Conversation

@owenjbendon-creator

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TOOLS-D3D12-RUN-FPS (#2570 (comment))

What and why

A game-run test compares two runs (#2464, part A), and two runs of the game never show the same scenes for the same time. Their plain medians then mislead: the run that spent its time in a busy street reads slower than the one that stood in a room, whatever was changed.

tools/d3d12_run_fps.py reads the frame line the D3D12 runtime logs every few seconds (d3d12/crates/leonida-gpu/src/host.rs: fps, ms a frame, preparing, copies, waiting on the GPU, copying back, draws a frame) from the launcher's log, 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;
  • the median frame rate per bucket of draws a frame.

--compare <log B> puts a second run beside the first, bucket by bucket, and gives the change only for buckets with enough samples in both runs (--min-samples, 5 by default). --json prints the same numbers as JSON.

It never prints a log line, a program name, an address or the path of a log (not in an error message either), so its output can go in a RUN block or a pull request while the log stays on the machine that made it. Standard library only, run with python -I. It reads UTF-8 and UTF-16 logs (a PowerShell redirection writes UTF-16), strips terminal colour codes and skips a truncated last line. 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.

This adds a tool and five lines to the Reporting section of docs/running.md. No runtime or translator code is touched.

An example of why the buckets matter (numbers only)

Two real runs of one save on one machine, with different builds of the layer:

A B
Plain median 15.6 fps 16.2 fps
Median draws a frame 5,132 7,676
3000-4999 draws 16.3 fps (48 samples) 24.6 fps (5)
5000-6999 draws 15.6 fps (44) 20.1 fps (22)
7000-8999 draws 16.1 fps (8) 16.9 fps (15)
9000+ draws 12.2 fps (20) 14.8 fps (27)

The plain medians say "the same". By bucket B is 51%, 29%, 5% and 21% faster: it had spent its time in busier scenes.

Tested

  • python -I tests/test_d3d12_run_fps.py: 16 tests on synthetic lines written in the shape of the runtime's format string (the frame line read field by field, other lines and colour codes ignored, a line cut short just before its end, a UTF-16 log, text that only looks like a frame line refused, menus left out, bucket edges, tenths by nearest rank, the whole text of one run, the comparison where plain medians mislead, the samples a bucket needs, a run at 0 fps not divided by, text and JSON agreeing, no log text and no path printed, bad options refused). No game files, no GPU.
  • On main the test file fails at import: the tool does not exist there.
  • Eight deliberate breakages of the tool (the tenth rounded down, menus counted, the path printed in an error, and so on) each fail a test.
  • python -I tests/test_text_write_line_endings.py: passes (the tool writes no file).
  • python -I scripts/check_no_game_data.py tools/d3d12_run_fps.py tests/test_d3d12_run_fps.py docs/running.md: clean.
  • Run by hand on real logs of D3D12-runtime runs (the example above).

Not tested: a log from a current main build of leonida.exe on this machine. The example logs are from builds of the same lineage with the same frame line; the regular expression follows the format string on main as of adfb3821a.

GPUs tested: none needed (no GPU code). The example runs were made on an NVIDIA GeForce RTX 3090, driver 610.88, Windows 10 Pro 22H2 (19045), Ryzen 7 9800X3D.

AI-assisted: yes (Claude Code, Claude Fable 5.2). A second, fresh session reviewed the diff before this was opened; what it found (thin assertions on the printed text, a typed path echoed in an error, an unbounded pattern, an option that could mislabel a bucket) is fixed in this one commit.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…ns 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>
@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2594 | head 9f7587e (merged cleanly with main adfb382) | python -I tests/test_d3d12_run_fps.py -v + live Windows PowerShell Out-File -Encoding unicode (UTF-16LE BOM + CRLF) --compare CLI probe + python -I tests/test_docs_cli_flags.py | red on main: ModuleNotFoundError: No module named 'd3d12_run_fps' (tools/d3d12_run_fps.py absent on main) | green on PR+main: 16 ran, OK (test_d3d12_run_fps.py), live PowerShell UTF-16LE BOM + CRLF --compare exited 0 (+25% bucket delta, 0 log-line or file-path leaks), 4 ran, OK (test_docs_cli_flags.py), 17 ran, OK (test_docs_links.py), and 5 ran, OK (test_docs_repo_paths.py) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited 9f7587e193 (tools/d3d12_run_fps.py, tests/test_d3d12_run_fps.py, and docs/running.md) on Windows 11 — first execution of this PR — confirming FRAME_LINE matches the tracing::info! format string in d3d12/crates/leonida-gpu/src/host.rs field-for-field, strips ANSI colour sequences, handles both UTF-8 and Windows PowerShell UTF-16LE BOM + CRLF logs, redacts input paths on OSError, and never echoes raw log text. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, tests/test_docs_encoding.py, and scripts/check_no_game_data.py.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Tested 9f7587e19 merged (no commit) with main aa918e5d9: Python 3.12.4, Rust 1.98.1, Windows 11 10.0.26300, CPU only (no game run). check_no_game_data.py is clean.

Blocker: the branch carries much more than this PR's topic. git log aa918e5d9..9f7587e19 lists 16 commits. Only the last one (9f7587e19, tools/d3d12_run_fps.py) is the TOOLS-D3D12-RUN-FPS item. The others are:

Merging this as is would land all of the above, including #625 and #1256 under another PR's name. Suggest rebasing it to the d3d12_run_fps commit alone, with the pacing changes as their own pull request.

What I measured on the merge, for the record:

  • Python: the 8 touched test files pass. The exception is test_progress_dashboard.py, whose one README failure (test_default_repo_is_the_one_the_readme_clones) is the same on plain main. With the tools back to main, all 8 fail (for test_d3d12_run_fps.py, the module does not exist).
  • Rust: cargo test -p leonida-gpu --lib --locked gives 517 passed and 0 failed on the merge, against 515 and 0 on main. The 2 new tests pass (fg::reflex_frame_tests::reflex_frames_follow_the_titles_events, smooth::tests::presents_are_held_to_a_fraction_of_the_running_mean). Warnings are unchanged (10). The pacing itself is not checked in the title.

AI-assisted (Claude Code).

@owenjbendon-creator

Copy link
Copy Markdown
Contributor Author

Thanks for testing this. The branch is one commit on top of main, though; nothing else comes with it.

  • GitHub's own view of this pull request: 1 commit, 3 files, +512 −0, base adfb3821a.
  • git rev-list --count origin/main..9f7587e19 gives 1.

aa918e5d9 is an older main: it is an ancestor of adfb3821a, 24 commits back (git rev-list --count aa918e5d9..adfb3821a). So git log aa918e5d9..9f7587e19 also lists what main gained in between. The merges of #625, #1256, #1205, #1022 and #1001, and the three leonida-gpu commits (bd06eb904, c7fcf49a7, eaecc6ac1), are already on main (git merge-base --is-ancestor <commit> origin/main holds for each). They are not part of this pull request and merging it does not land them again.

Merging this adds only tools/d3d12_run_fps.py, tests/test_d3d12_run_fps.py and the paragraph in docs/running.md. No rebase is needed: it merges cleanly with main as of a9e247cd6.

AI-assisted (Claude Code, Claude Fable 5.2).

@timbot103 timbot103 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static audit of 9f7587e against main 48bae6c. Please fix argument-error redaction before merge. At tools/d3d12_run_fps.py:174, omitting --compare between two log arguments makes argparse echo the second path to stderr. Invalid --min-samples values are echoed too.

At tools/d3d12_run_fps.py:65, anchor the match to the start of a bare frame line or the host INFO message. At line 45, an EOF cut after the draw count still produces a sample. Add coverage for both cases. At line 131, include the texture and copy-back MB medians in text so it matches JSON.

AI-assisted.

…here the logger wrote them, an unfinished last line skipped (TOOLS-D3D12-RUN-FPS)

From the review of 9f7587e:

- 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>
@owenjbendon-creator

Copy link
Copy Markdown
Contributor Author

Thanks, all four were right. Fixed in 016554bef (a second commit, so the first review's head stays as it was):

  • Argument errors no longer give back what was typed. A second log without --compare now reads 1 argument not understood: one log, and a second after --compare; unknown arguments are counted, not quoted. --min-samples has its own type, whose error is fixed text (a whole number, 1 or more), and options cannot be abbreviated. The only argparse messages left are its own fixed ones (expected one argument and the like).
  • A frame line counts only where the logger wrote it: 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, after other text, at another level or under another target are not read.
  • A cut after the draw count gives no sample. A last line without its line end is skipped whatever it holds, and the pattern now asks for the words that follow the count (, dropped ), so the same cut with a line end is refused too.
  • The text gives the textures' MB and the copy-back's MB, as the JSON does; a test checks the text names every median the JSON has.

Tested: python -I tests/test_d3d12_run_fps.py, 19 tests (three new: a frame line counts only where the logger wrote it; a last line without its end is skipped; no error gives back what was typed). test_text_write_line_endings.py, test_docs_cli_flags.py and check_no_game_data.py on the changed files pass. Each of the new rules, broken on purpose in a copy, fails a test.

AI-assisted (Claude Code, Claude Fable 5.2).

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

#2594 | head 016554b (merged cleanly onto origin/main 791899f) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Independent Verification (Windows 11)

  • Diff & format-string parity audit: Inspected 100% of the diff on current head 016554bef3 across docs/running.md, tools/d3d12_run_fps.py, and tests/test_d3d12_run_fps.py, and verified FRAME_LINE matches d3d12/crates/leonida-gpu/src/host.rs's tracing::info! frame summary format string ({fps:.1} fps, {ms:.1} ms/frame ({cpu:.1} preparing: copies {copy_ms:.1} ms {copy_mb:.1} MB, textures {texture_ms:.1} ms {texture_mb:.1} MB; {gpu:.1} on the GPU; {back_ms:.1} copying back {back_mb:.1} MB), {draws:.0} draws/frame, ...). python -I scripts/check_no_game_data.py docs/running.md tools/d3d12_run_fps.py tests/test_d3d12_run_fps.py passed (rc=0).
  • Verification on native Windows 11 (#2594 + origin/main 791899f652):
    • python -I tests/test_d3d12_run_fps.py -v -> 19/19 passed (0 skipped, OK, 0.208s), covering UTF-8 and UTF-16 BOM PowerShell log decoding, ANSI escape stripping, truncated last-line handling, bucketed --compare like-for-like FPS comparisons, allow_abbrev=False, and strict path/log-text suppression in both stdout and error diagnostics.
    • python -I tests/test_ci_registration.py -> 18/18 passed (OK)
    • Doc verification suites: test_docs_table_rows.py (2/2), test_docs_repo_paths.py (5/5), test_docs_encoding.py (1/1), test_docs_env_vars.py (5/5) -> all OK.

@lixonik

lixonik commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

I ran all 19 synthetic tests on Windows 10, CPython 3.12.1, for head 016554bef3697bcb705f9ea3360fabeb9a4841b5 merged into main 04f484006e. All passed. One argument-redaction case remains.

python -I tools/d3d12_run_fps.py baseline.log --json=synthetic-private-name exits 2 and prints argument --json: ignored explicit argument 'synthetic-private-name' to stderr. --help=synthetic-private-name does the same. No input file is needed. These are recognized flags, so argparse reports the error before parse_known_args can return an unknown-argument list.

Please redact the argument text for malformed no-value flags too, and cover --json=<marker> and --help=<marker> alongside the existing malformed numeric options.

AI-assisted. Codex (GPT-6).

…ts (TOOLS-D3D12-RUN-FPS)

From the review of 016554b: `--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>
@owenjbendon-creator

Copy link
Copy Markdown
Contributor Author

Thanks, that was a real gap: argparse raises that error for a known flag before parse_known_args returns, so counting the unknown arguments could not catch it. Fixed in befe3aa13, and closed for the whole class rather than for the two flags:

  • 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 a separate fail(), unchanged.
  • python -I tools/d3d12_run_fps.py baseline.log --json=synthetic-private-name now prints argument --json: takes no value, and --help=synthetic-private-name prints argument -h/--help: takes no value.

Tested: python -I tests/test_d3d12_run_fps.py, 22 tests. New: --json=<marker>, --help=<marker>, bad --edges and --min-samples values, an unknown flag and a missing log, each with a plain marker, one with quotes in it and one with a space; a message the list does not know, named and unnamed; and the fixed texts checked against what the argument types raise. Letting argparse's messages through in a copy fails those tests. test_text_write_line_endings.py, test_docs_cli_flags.py and check_no_game_data.py on the changed files pass.

AI-assisted (Claude Code, Claude Fable 5.2).

@lixonik

lixonik commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Rechecked befe3aa137c7e0f729906a1438b99dfacb8f669a merged into main c8bf0e7b65 on Windows 10 and CPython 3.12.1. All 22 tests passed. The new malformed-flag test failed with the previous parser and passed with this update. Both --json=<marker> and --help=<marker> now report the flag error without the supplied value.

AI-assisted. Codex (GPT-6).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants