code wiki / _hdl_build / nx_perf_sentinel.nx
nx_perf_sentinel.nx
buildroot/runtime/_hdl_build/nx_perf_sentinel.nx
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
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
structs
| none |
consts
| 34 | const PS_MAGIC_32768: i64 = 32768 |
| 36 | const PS_WINDOW_MS: i64 = 2000 |
| 37 | const PS_MAX_PROCS: i64 = 2048 |
| 38 | const PS_HZ: i64 = 100 // kernel USER_HZ for utime/stime |
| 39 | const PS_LOG_PATH: *u8 = "/tmp/nishi_perf_sentinel.log" as *u8 |
| 40 | const PS_CONF_DEF: *u8 = "/tmp/nishi_perf_budgets.conf" as *u8 |
| 42 | const PS_ACT_LOG: i64 = 1 |
| 43 | const PS_ACT_ESCALATE: i64 = 2 |
| 44 | const PS_ACT_KILL: i64 = 3 |
functions
| 46 | func ps_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 47 | func ps_puts(s: *u8) -> i64 { sys_write(1, s, ps_slen(s)); return 0 } |
| 48 | func ps_putn(v: i64) -> i64 |
| 62 | func ps_append(dst: *u8, off: i64, s: *u8) -> i64 |
| 67 | func ps_append_n(dst: *u8, off: i64, v: i64) -> i64 |
| 82 | func ps_dec(buf: *u8, i: i64, n: i64, ip: *i64) -> i64 |
| 101 | func ps_read_stat(pid: i64, comm: *u8, statec: *u8, ticks: *i64, start: *i64) -> i64 |
| 150 | func ps_uptime_s() -> i64 |
| 160 | func ps_list_pids(pids: *i64) -> i64 |
| 199 | func ps_has(hay: *u8, needle: *u8) -> i64 |
| 217 | func ps_budget(cfg: *u8, cfgn: i64, comm: *u8, |
| 270 | func main(argc: i64, argv: *i64) -> i64 |