Skip to content

dstorage, fs: LEONIDA_IO_TRACE logs every read the title asks for, flushed as it goes (RT-IO-TRACE) - #1931

Open
kawaii-shakal wants to merge 4 commits into
ProjectLeonida:mainfrom
kawaii-shakal:io-trace
Open

kawaii-shakal wants to merge 4 commits into
ProjectLeonida:mainfrom
kawaii-shakal:io-trace

Conversation

@kawaii-shakal

@kawaii-shakal kawaii-shakal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as RT-IO-TRACE: #1608 (comment)

Problem

When a boot stops, --trace names the files the title opened (the first 600 opens), but not what it was reading. Most of the reading goes through DirectStorage requests and ReadFile on files opened long before the stop. In a 1.0.2.1 boot here, the last open came 4 minutes before the device loss.

Change

With LEONIDA_IO_TRACE=<file>, every read is one line, starting with the local time (as the mem-probe lines do):

hh:mm:ss.mmm ds G:\example.rpf off=0x1000 src=4096 dst=16384 zlib=1 bcpack=0 name=-
hh:mm:ss.mmm rf \\?\F:\...\data.bin off=0x1000 size=512
  • ds: each DirectStorage request at EnqueueRequest, with file (or <memory>), file offset, source and destination sizes, zlib, BCPack and the request's name. The name pointer is the title's, so it is copied under SEH.
  • rf: each ReadFile, ReadFileEx and ReadFileScatter on a disk file, with path, offset (the OVERLAPPED's, else the handle's position) and size. The path is asked of the handle every time, because a handle value is reused after a close.
  • On disk at once: every line is flushed, and the file is opened shared for reading (_wfsopen(..., _SH_DENYNO)). The last reads before a crash or device loss are on disk, and the file can be watched during the boot.

It is off by default; without the variable nothing is formatted. runtime/shims/io_trace.h implements it, with hooks in dstorage.cpp and file_system.cpp. docs/boot.md documents the variable.

Tested (Windows 11 Pro 26300, VS 2026 RelWithDebInfo)

  • CTest: io_trace covers positioned, overlapped and reused-handle reads, DirectStorage lines with a good, a bad and a null name pointer, pipes left out, and reading the trace while it is open. dstorage and file_system pass too.
  • Real boot: an earlier build of the same hooks ran during a 1.0.2.1 retail boot on an RTX 5070 Ti. It wrote about 90,000 lines, and the last ones showed the streaming at the world start right before the device loss: anim.rpf, levels.rpf, core_bvh4.rpf and packs.rpf, with all reads stopping at the moment of the loss.

🤖 Generated with Claude Code

…ushed as it goes (RT-IO-TRACE)

When a boot stops, the startup trace names the files the title opened, but most of its reading goes
through DirectStorage requests and ReadFile on files it opened long before. With LEONIDA_IO_TRACE=<file>,
each DirectStorage request (file, offset, sizes, zlib/BCPack, request name) and each ReadFile, ReadFileEx
or ReadFileScatter on a disk file (path, offset, size) is one line with the local time.

The line is flushed at once into a file shared for reading, so the last reads before a crash are on disk
and can be watched while the game runs. Paths are asked of the handle each time, because a handle value
is reused after a close. io_trace_test covers positioned, overlapped and reused-handle reads, DirectStorage
lines with good and bad name pointers, and pipes being left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict resolution assisted by Codex.
@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main d48a957bb + a6e0360f44 (claim #2570#issuecomment-7238954420):

  • Line-by-line diff audit: Clean (docs/boot.md, runtime/CMakeLists.txt, runtime/shims/dstorage.cpp, runtime/shims/file_system.cpp, runtime/shims/io_trace.h, runtime/test/io_trace_test.cpp); opens LEONIDA_IO_TRACE with _SH_DENYNO, flushes timestamped ds and rf read lines under a mutex, queries GetFinalPathNameByHandleW per disk handle, and guards request.Name reads with __try / __except. check_no_game_data.py, test_docs_encoding, test_docs_links, and LEONIDA_IO_TRACE env-var doc coverage all pass.
  • Red (d48a957bb + PR test): io_trace_test.cpp fails to build (rc=2, fatal error C1083: Cannot open include file: 'io_trace.h': No such file or directory).
  • Green (d48a957bb + a6e0360f44 merge): Auto-merges cleanly across all 4 modified files (rc=0), compiles io_trace_test.exe with 0 warnings under /W4 /permissive- and passes (io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading, rc=0), and builds/passes full dstorage_test.exe (rc=0) while emitting 2,855 live flushed ds / rf trace lines under LEONIDA_IO_TRACE.

AI-assisted.

@Tauwni

Tauwni commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

With clang-cl, the new io_trace test crashes instead of catching the unreadable name: wine: Unhandled page fault on read access to 0000000000000010, in rt::io_trace::copy_name (runtime/shims/io_trace.h:70) called from io_trace_test.cpp:60, safe_name(reinterpret_cast<const char*>(16)). Fails 3/3 runs (MEASURED; Apple M3, macOS 26.5.1, Wine 11.0, clang-cl cross-build, head 29141b471 merged onto main ef02e9a9b).

runtime/CMakeLists.txt says why next to dstorage.cpp: "These sources use __try to handle access violations. MSVC always catches them; clang-cl needs asynchronous exceptions". dstorage.cpp, the runtime file that calls safe_name, already gets /EHa there, so the runtime side is covered; the new io_trace_test target does not. With the same option on it,

target_compile_options(io_trace_test PRIVATE /W4 /permissive- /utf-8 $<$<CXX_COMPILER_ID:Clang>:/EHa>)

the test passes, 3/3 runs (MEASURED, same machine). With MSVC it passes as is, which matches the MSVC run above; I have not run MSVC myself.

Not checked by a second agent or human yet.

AI-assisted (Claude Code).

…aught (RT-IO-TRACE)

copy_name reads the title's name inline in its __try. MSVC always catches that fault; clang-cl only with
asynchronous exceptions, and io_trace_test was built without them (dstorage.cpp has them through its source
property), so under clang-cl the safe_name(16) check ended the test with an unhandled page fault. Reported by
Tauwni on ProjectLeonida#1931 (clang-cl cross build, Wine 11). Reproduced with clang-cl 21 under Wine: 3 of 3 runs crash at
0x10 without /EHa, 3 of 3 pass with it. The header comment now says a caller needs /EHa under clang-cl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
@kawaii-shakal

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed and fixed in 7d571f7: io_trace_test now gets $<$<CXX_COMPILER_ID:Clang>:/EHa> as you suggested, and the comment on copy_name says a caller needs it under clang-cl (dstorage.cpp, the only caller in the runtime, already has it through its source property, so the shim itself was not affected). Reproduced here with clang-cl 21 + xwin under Wine, same compile flags as the CMake target: without /EHa 3/3 runs end in Unhandled page fault on read access to 0000000000000010, with it 3/3 pass. MSVC is unchanged (the expression is empty there).

AI-assisted (Claude Code); I ran the builds and checked the results.


Generated by Claude Code

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

#1931 | head 7d571f7 (merged cleanly onto origin/main c8bf0e7) | Windows 11 (10.0.26200.9974), MSVC 19.44.35228 (x64), Python 3.12.10 | AI-assisted: yes

Summary — PASS (Re-verification of updated head 7d571f75b7e1)

Re-verified 7d571f75b7e126e69f8eb61d151ac7f11d866803 merged cleanly onto origin/main (c8bf0e7b6568f471b42540010e335ca6413d4c58, git merge-tree --write-tree exit 0) on native Windows 11 (x64).

Red -> Green Verification

  1. Red (origin/main c8bf0e7b65):
    • runtime/shims/io_trace.h and runtime/test/io_trace_test.cpp are absent on origin/main, and neither file_system.cpp nor dstorage.cpp emits unbuffered LEONIDA_IO_TRACE records.
  2. Green (origin/main + #1931):
    • Standalone test build & execution (MSVC 19.44.35228, /std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8 /link /OPT:NOREF):
      • runtime/test/io_trace_test.cpp compiled cleanly (0 warnings) and passed in 0.075s (rc=0: io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading), covering unset/empty LEONIDA_IO_TRACE, LEONIDA_IO_TRACE=- (stderr), FILE_SHARE_READ concurrent open while tracing is active, positioned & OVERLAPPED ReadFile lines (rf), DirectStorage file/memory/unreadable-name request lines (ds), unbuffered write-through across abrupt TerminateProcess without atexit/fflush, and multi-threaded atomic WriteFile line integrity.
    • Shim call-site compilation (MSVC 19.44.35228, /c /std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8):
      • runtime/shims/file_system.cpp and runtime/shims/dstorage.cpp both compiled cleanly with io_trace.h wired in (rc=0, 0 warnings).
    • CMake & Docs Gates:
      • python tests/test_ctest_registration.py -> OK
      • docs/boot.md relative-link & anchor check -> 0 issues

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR

  • Base: main aa918e5d9 + PR head 7d571f75b
  • Test: ctest -R ^io_trace$
  • Red on main: the new test does not compile on main (io_trace.h is added by the PR)
  • Green with the PR: passes; package builds, full ctest shows no new failure (d3d12_queue_handover_shared_queue failed once under load and passes on a serial rerun)
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

Note: shares runtime/CMakeLists.txt with the open #2566; a rebase may be needed if #2566 lands first.

AI-assisted (Claude Code, Claude Opus 5.5).

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