code wiki / (root) / nx_perf_probe.nx

nx_perf_probe.nx

buildroot/runtime/nx_perf_probe.nx

6437 B184 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind probetopic perf
docsdependenciesstructsconstsfunctions

about

nx_perf_probe.nx -- substrate performance counter primitive. Cardinal: feedback-systemic-injection-everything-zero-runtime-overhead. Same three-layered pattern as nx_bit_provenance / nx_race_telemetry: (1) Born-into-build: callers use nx_perf_tick_start / tick_end (or the wrap_call helpers below). (2) Retroactive: future self-host IR pass injects entry/exit calls driven by `// nx_perf: budget_ns=...` annotations on function definitions. (3) Zero runtime cost when --strip perf: NX_PERF_ACTIVE compile-folded to 0 + entire machinery DCE'd. Storage: ring buffer of (function_tag, start_ns, end_ns, iter) records. No per-tick syscalls; nx_perf_now() uses sys_clock_gettime_mono once per tick. API surface: let tk: i64 = nx_perf_tick_start(NX_PERF_TAG_MATMUL) // ... work to time ... nx_perf_tick_end(tk) -- elapsed recorded nx_perf_drain(out: *i64, cap: i64) -> i64 nx_perf_n_records() -> i64 nx_perf_enable() / nx_perf_disable() / nx_perf_is_active() Each tick uses ONE clock syscall + one ring-buffer write. No startup cost. No ledger allocation until first tick.

dependencies 1 imports · 0 importers

syscalls.nx nx_perf_probe.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_perf_init nx_perf_disable nx_perf_tick_start nx_perf_init ↻ nx_perf_now_ns nx_perf_n_records nx_perf_enable nx_perf_now_ns ↻ nx_perf_tick_end nx_perf_now_ns ↻ nx_perf_drain nx_perf_init ↻

structs

none

consts

32const NX_MAGIC_4096: i64 = 4096
33const NX_MAGIC_1000000000: i64 = 1000000000
34const NX_MAGIC_1024: i64 = 1024
42const NX_PERF_REC_SIZE: i64 = 32 // 4 i64 fields
43const NX_PERF_RING_BYTES: i64 = 32768 // 1024 records

functions

55func nx_perf_init() -> i64
67func nx_perf_enable() -> i64 { NX_PERF_ACTIVE = 1; return 0 }
called by 1: main
68func nx_perf_disable() -> i64 { NX_PERF_ACTIVE = 0; return 0 }
called by 1: main
69func nx_perf_is_active() -> i64 { return NX_PERF_ACTIVE }
73func nx_perf_now_ns() -> i64
83func nx_perf_tick_start(tag: i64) -> i64
called by 1: main calls 2: nx_perf_initnx_perf_now_ns
102func nx_perf_tick_end(handle: i64) -> i64
called by 1: main calls 1: nx_perf_now_ns
115func nx_perf_drain(out: *i64, max_records: i64) -> i64
called by 1: main calls 1: nx_perf_init
135func nx_perf_n_records() -> i64 { return NX_PERF_RING_HEAD }
called by 1: main
140func main() -> i64