nx_perf_probe.nx
buildroot/runtime/nx_perf_probe.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 32 | const NX_MAGIC_4096: i64 = 4096 |
| 33 | const NX_MAGIC_1000000000: i64 = 1000000000 |
| 34 | const NX_MAGIC_1024: i64 = 1024 |
| 42 | const NX_PERF_REC_SIZE: i64 = 32 // 4 i64 fields |
| 43 | const NX_PERF_RING_BYTES: i64 = 32768 // 1024 records |
functions
| 55 | func nx_perf_init() -> i64 |
| 67 | func nx_perf_enable() -> i64 { NX_PERF_ACTIVE = 1; return 0 } called by 1: main |
| 68 | func nx_perf_disable() -> i64 { NX_PERF_ACTIVE = 0; return 0 } called by 1: main |
| 69 | func nx_perf_is_active() -> i64 { return NX_PERF_ACTIVE } |
| 73 | func nx_perf_now_ns() -> i64 |
| 83 | func nx_perf_tick_start(tag: i64) -> i64 |
| 102 | func nx_perf_tick_end(handle: i64) -> i64 |
| 115 | func nx_perf_drain(out: *i64, max_records: i64) -> i64 |
| 135 | func nx_perf_n_records() -> i64 { return NX_PERF_RING_HEAD } called by 1: main |
| 140 | func main() -> i64 |