Gather the log lines of a quarter of a second and write them at once.

The log thread wrote as soon as it woke, which outside a burst is once for every line: each line woke it and was a write of its own to the log file and the console. It now waits a quarter of a second from the first line it finds, or until the queue is half full, and writes what was queued by then at once, so the log is up to that much behind the game. What is being gathered stays in the queue, so a fatal error, a crash report and an exit write it out before their own lines as before; a game ended from outside loses those last lines. The queue's test checks the gathering, the half-full write and that a process which ends at once, by an exit or as a fatal error does, leaves every line in its file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 15:11:59 -05:00
parent 1c975316a3
commit cc0b467a2c
6 changed files with 143 additions and 16 deletions

View File

@@ -41,10 +41,11 @@ from other projects, with its license, is listed in [THIRD_PARTY_NOTICES.md](../
variables and written back when the in-game menu changes it. The menu and the performance overlay are Dear ImGui,
drawn into the swapchain image (`runtime/ui/`); their text is in `ui_text.c`.
- Log: in a game run the lines go through a queue to a thread that writes them (`runtime/logq.c`), so a stalled
write to the log file or the console does not hold the thread that logged. A thread's lines reach the log in the
order it logged them: a line waits for the queue's lock, and one that finds the queue full is written after
everything queued before it. A fatal error, the crash report and the end of the process write the queue out first
(`rt_log_sync`). `NX2NAVI_LOG_ASYNC=0` writes each line where it is logged.
write to the log file or the console does not hold the thread that logged. The log thread gathers the lines of
a quarter of a second, or half a queue, into one write, so the log is up to that much behind the game. A thread's
lines reach the log in the order it logged them: a line waits for the queue's lock, and one that finds the queue
full is written after everything queued before it. A fatal error, the crash report and the end of the process write
the queue out first (`rt_log_sync`). `NX2NAVI_LOG_ASYNC=0` writes each line where it is logged.
- Co-op (`coop.c`, `coop_proto.c`, [coop.md](coop.md)): a host thread with a UDP socket to a relay (`tools/coop_relay.py`),
rooms of up to 8 players and a channel for messages between them; it never holds a virtual core.
- OS calls the host makes go through `runtime/platform/` (`platform.h`, `win32.c`).

View File

@@ -373,9 +373,14 @@ A change to the log queue (`runtime/logq.c`) passes `python tests\logq_check.py`
layer and a destination of its own: 160,000 lines from eight threads arrive whole and in each thread's order, a line
logged while the queue's lock is taken waits and does not pass the lines queued before it, a destination that takes
30 ms a write does not hold the threads that log, the line about slow writes comes once in ten seconds, a destination
that stops while four times the queue's size is logged loses nothing, and `logq_sync` returns with everything written.
The test passes on a busy machine too: it waits for the queue to empty instead of for a time, and counts slow lines
instead of timing one. No game files.
that stops while four times the queue's size is logged loses nothing, lines logged together are written in one write
a quarter of a second after the first and not before, a queue that is half full is written at once, and `logq_sync`
returns with everything written, the lines the log thread was still gathering included. The program then runs twice
more as a process that logs 200 lines to a file and ends at once, by an exit and as a fatal error does: each file
holds every line, and the fatal line last.
The test passes on a busy machine too: it waits for the queue to empty instead of for a time, counts slow lines
instead of timing one, leaves out a check its own thread was too late for, and tries the half-full write three times.
No game files.
A change to the button prompts (`tools/make_romfs_patches.py --prompts`, `tools/button_icons.py`) passes
`.venv-py314\Scripts\python tests\romfs_prompts_test.py`, which runs the tool on a RomFS it makes itself (no game