code wiki / _hdl_build / nx_perf_sentinel.nx

nx_perf_sentinel.nx

buildroot/runtime/_hdl_build/nx_perf_sentinel.nx

13650 B353 linesdepth 2pulls 3 transitivereach 0 importersview sourcekind tooltopic perf
docsdependenciesstructsconstsfunctions

about

nx_perf_sentinel.nx -- the team's BOTTLENECK/LIVENESS organ. Operator 2026-06-10: "slowness anywhere in our entire ecosystem is a total failure, build the team to identify these bottlenecks and dead ends and infinite loops etc and handle them." What it does (one re-runnable pass; the loop runs it on a beat): 1. samples /proc twice (SENTINEL_WINDOW_MS apart) and computes REAL per-process CPU%% from utime+stime deltas -- no vibes, kernel truth 2. classifies each process against a BUDGET TABLE (config file, NO magic numbers in code -- Cardinal 11): SPIN cpu%% >= spin_pct (the nx_signaling 100%%-spin class, bd.t/ovw multi-day runaways) RUNAWAY cpu%% >= hot_pct AND age >= age_s (hot for days) 3. HANDLES per the budget action: log -> sentinel log line; escalate -> ESCALATE line (the PM/loop dispatcher's queue); kill -> nx_kill(pid,9) ONLY when the budget line explicitly says so (governed: default budgets never kill -- a human/PM line opts in) 4. exit code = number of violations (0 = ecosystem clean) so it IS its own gate and cron-able health check. Budget config (default /tmp/nishi_perf_budgets.conf, overridable argv[1]): # comm-substring spin_pct hot_pct age_s action(log|escalate|kill) * 97 80 86400 escalate nx_signaling 90 50 3600 escalate '*' = default row. First matching row wins; comm match = substring. Composes: nx_syscalls (getdents64/read/kill), the nx_loop_monitor verdict->handle pattern, nx_sysload's /proc-truth doctrine. license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_kill_portable.nx nx_perf_sentinel.nx

imports: nx_syscalls.nxnx_kill_portable.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close ps_slen ps_list_pids sys_openat_rd ↻ sys_mmap ↻ sys_getdents64 sys_close ↻ ps_read_stat sys_mmap ↻ ps_append ps_append_n sys_read_file ↻ ps_dec sys_sleep_ms sys_mmap ↻ sys_munmap ps_uptime_s sys_mmap ↻ sys_read_file ↻ ps_dec ↻ sys_openat_append ps_budget sys_mmap ↻ ps_dec ↻ ps_has ps_slen ↻ ps_append ↻ ps_append_n ↻ sys_write nxk_kill sys_close ↻ ps_puts sys_write ↻

structs

none

consts

34const PS_MAGIC_32768: i64 = 32768
36const PS_WINDOW_MS: i64 = 2000
37const PS_MAX_PROCS: i64 = 2048
38const PS_HZ: i64 = 100 // kernel USER_HZ for utime/stime
39const PS_LOG_PATH: *u8 = "/tmp/nishi_perf_sentinel.log" as *u8
40const PS_CONF_DEF: *u8 = "/tmp/nishi_perf_budgets.conf" as *u8
42const PS_ACT_LOG: i64 = 1
43const PS_ACT_ESCALATE: i64 = 2
44const PS_ACT_KILL: i64 = 3

functions

46func ps_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 3: ps_putsps_hasmain
47func ps_puts(s: *u8) -> i64 { sys_write(1, s, ps_slen(s)); return 0 }
called by 1: main calls 2: sys_writeps_slen
48func ps_putn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
62func ps_append(dst: *u8, off: i64, s: *u8) -> i64
called by 2: ps_read_statmain
67func ps_append_n(dst: *u8, off: i64, v: i64) -> i64
called by 2: ps_read_statmain
82func ps_dec(buf: *u8, i: i64, n: i64, ip: *i64) -> i64
101func ps_read_stat(pid: i64, comm: *u8, statec: *u8, ticks: *i64, start: *i64) -> i64
150func ps_uptime_s() -> i64
called by 1: main calls 3: sys_mmapsys_read_fileps_dec
160func ps_list_pids(pids: *i64) -> i64
199func ps_has(hay: *u8, needle: *u8) -> i64
called by 1: ps_budget calls 1: ps_slen
217func ps_budget(cfg: *u8, cfgn: i64, comm: *u8,
called by 1: main calls 3: sys_mmapps_decps_has
270func main(argc: i64, argv: *i64) -> i64