mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 15:49:57 -04:00
Write the log from a thread of its own, so a stalled write no longer holds the thread that logged.
Every log line was two writes on the thread that logged it, to stderr and to the log file. Such a write can stall for tens or hundreds of milliseconds (a busy disk, a virus scanner, a console or a pipe that is slow to take it), and the render thread logs too: a frame it spent in a write was a hitch with nothing else to show for it. In a game run the lines now go into a queue that a log thread writes out in order (runtime/logq.c). A fatal error, the crash report and the end of the process write the queue out on their own thread first and write their own lines directly, so nothing is lost to an exit. A thread that finds the queue's lock held for long, or the queue full, writes its line itself. NX2NAVI_LOG_ASYNC=0 writes every line where it is logged, as before. Every write is timed in both modes: a "log: ... writes of the log took over 2 ms" line counts the slow ones, gives the longest and says whose time they took. tests/logq_check.py checks order and completeness with eight threads, a slow destination, a stopped destination with the queue full, and the synchronous flush. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -289,6 +289,7 @@ void plat_aligned_free(void *p);
|
||||
|
||||
// ---- process
|
||||
_Noreturn void plat_exit(int code); // ends the process at once: other threads stop, no atexit handlers run
|
||||
extern void (*plat_exit_hook)(void); // called first by plat_exit when set (main.c: the queued log lines)
|
||||
int plat_setenv(const char *name, const char *value); // value NULL removes it; 1 on success
|
||||
uint32_t plat_process_id(void);
|
||||
// CPU time of the process since it started (user and kernel), and wall time since it started, in ns; 0 when unknown.
|
||||
|
||||
Reference in New Issue
Block a user