code wiki / (root) / nx_log_v2.nx

nx_log_v2.nx

buildroot/runtime/nx_log_v2.nx

6047 B168 linesdepth 4pulls 4 transitivereach 1 importersview sourcekind librarytopic log
docsdependenciesstructsconstsfunctions

about

nx_log_v2.nx -- single-syscall fast emit for real-time competitions. v1 (nx_log.nx) does ~7 sys_write calls per event (seq + level + space + tag + space + msg + newline). Each syscall is ~200ns on modern hardware, so v1 costs ~1.4us per event. In a CASC / SAT-COMP loop emitting 10k events/sec that's 14ms/sec = 1.4% CPU just on logging syscalls -- before even counting the format work. v2 formats the entire line into a single buffer, then issues ONE sys_write. Expected: ~200ns per event (7x faster). Below-min-level emit is a single load+compare, ~3ns. API mirrors v1's nx_log_emit so callers can swap in place. The NxLogContext struct from v1 is reused -- no schema break. Performance discipline per cardinal [[feedback-genealogy-source-lineage-runtime-one-step-ten-sec]]: EAT the logging cost (don't strip in production), but EAT_LESS_THAN_BEFORE.

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_log.nx nx_log_v2.nx nx_log_v2_test.nx

imports: nx_syscalls.nxnx_log.nx

imported by: nx_log_v2_test.nx

structs

none

consts

29const NX_LOG_V2_BUF_BYTES: i64 = 1024

functions

41func nx_log_v2_buf() -> *u8
called by 1: nx_log_v2_emit calls 1: sys_mmap
51func nx_log_v2_slen(s: *u8) -> i64
called by 1: nx_log_v2_emit
58func nx_log_v2_memcpy(dst: *u8, src: *u8, n: i64) -> i64
called by 1: nx_log_v2_emit
68func nx_log_v2_write_seq(buf: *u8, off: i64, seq: i64) -> i64
called by 1: nx_log_v2_emit
81func nx_log_v2_write_level(buf: *u8, off: i64, level: i64) -> i64
called by 1: nx_log_v2_emit
115func nx_log_v2_emit(ctx: *NxLogContext, level: i64,
160func nx_log_v2_info(tag: *u8, msg: *u8) -> i64
163func nx_log_v2_warn(tag: *u8, msg: *u8) -> i64
166func nx_log_v2_error(tag: *u8, msg: *u8) -> i64