nx_enginelab_lib.nx
buildroot/runtime/nx_enginelab_lib.nx
about
nx_enginelab_lib.nx -- THE SOVEREIGN ENGINE INSTRUMENT (library half).
WHAT THIS IS. The open-source engine-testing field ships five SEPARATE programs with five
SEPARATE capture formats: a frame debugger (draw calls + pipeline state), a CPU zone profiler
(nanosecond scopes, threads, allocations, lock waits), a telemetry overlay (frame pacing, lows,
stutter), a GPU scheduling visualiser (queue slices, vsync, CPU-bound vs GPU-bound), and an
automated visual-regression harness (golden images). Each is excellent alone.
THE DEFECT THE FIELD LIVES WITH, AND OUR EXCEED. Because those five captures are five files with
five clocks, A FRAME-TIME SPIKE CAN NEVER BE JOINED TO THE DRAW CALL THAT CAUSED IT. You see the
spike in one tool and go hunting in another, by hand, by eye. Here every subsystem writes into ONE
record layout on ONE clock, so the join is arithmetic rather than detective work: el_frame_attr
answers 'this frame cost 41ms; of that, N draws, X us of GPU queue, Y us of CPU root zones, Z us
of lock wait, B bytes allocated'. That is the whole reason for a single spine, and it is the
mechanism no separate-format tool can offer.
LAWS MADE STRUCTURAL HERE, not left to the caller to remember:
- NO SILENT CAPS. A full store REFUSES and counts the refusal (EL_H_DROP). Every report carries
dropped= so a truncated measurement can never read as a complete one.
- ABSTAIN, NEVER ACQUIT. Every verdict has a third state. A bound-verdict with no GPU evidence
returns UNKNOWN, not CPU-BOUND. A capture diff over ZERO draws returns UNMEASURABLE, not
'identical' -- the empty-set-passes defect wearing a profiler costume.
- THE REASON TRAVELS WITH THE COUNT. Errors are split by cause (non-monotonic clock, stack
overflow, end-without-begin), never merged into one number nobody can act on.
- COMPOSE, NEVER RE-IMPLEMENT. Rolling FPS is nx_fpsmeter (fm_init/fm_tick/fm_fps), the frame
budget is nx_frame_budget (fb_budget_us/fb_fits/fb_headroom_us) and image parity is
nx_visual_diff (vd_grid_parity). There is exactly one of each ruler in this estate and this
file adds none of them.
- THRESHOLDS ARE PARAMETERS. Every bar (bound occupancy, stutter multiple, golden pass line) is
an argument with a named default const, so it can be driven from conf and never hides in code.
license_tier: ORIGINAL No hardware writes (Rule 26): this reads and computes, it never programs
a device. Pure integer arithmetic, wasm-friendly, daemon-reusable.
dependencies 4 imports · 6 importers
imports: nx_syscalls.nxnx_fpsmeter.nxnx_frame_budget.nxnx_itoa_lib.nx
imported by: nx_enginelab.nxnx_enginelab_analysis.nxnx_enginelab_analysis_gate.nxnx_enginelab_gate.nxnx_enginelab_golden.nxnx_enginelab_store.nx
structs
| none |
consts
| 49 | const EL_I64: i64 = 8 // bytes per i64 |
| 50 | const EL_REC: i64 = 8 // i64 per record |
| 52 | const EL_F_KIND: i64 = 0 |
| 53 | const EL_F_TS: i64 = 1 // monotonic microseconds, caller-supplied |
| 54 | const EL_F_DUR: i64 = 2 // filled at close; EL_DUR_OPEN while a scope is open |
| 55 | const EL_F_TID: i64 = 3 // CPU thread id, or GPU queue id for EL_K_GPU |
| 56 | const EL_F_NAME: i64 = 4 // interned name id -- an id, never a string: no allocation in a hot loop |
| 57 | const EL_F_A: i64 = 5 // DRAW: pipeline id ALLOC: bytes GPU: submit ts |
| 58 | const EL_F_B: i64 = 6 // DRAW: vertex count ALLOC: address LOCK: owner tid |
| 59 | const EL_F_C: i64 = 7 // DRAW: state hash ZONE: child total us FRAME: frame ordinal |
| 61 | const EL_DUR_OPEN: i64 = -1 // a scope that has begun and not ended |
| 64 | const EL_K_FRAME: i64 = 1 |
| 65 | const EL_K_ZONE: i64 = 2 |
| 66 | const EL_K_GPU: i64 = 3 |
| 67 | const EL_K_DRAW: i64 = 4 |
| 68 | const EL_K_ALLOC: i64 = 5 |
| 69 | const EL_K_FREE: i64 = 6 |
| 70 | const EL_K_LOCK: i64 = 7 |
| 71 | const EL_K_VSYNC: i64 = 8 |
| 75 | const EL_H_CAP: i64 = 0 |
| 76 | const EL_H_N: i64 = 1 |
| 77 | const EL_H_DROP: i64 = 2 // records REFUSED because the store was full. Never silent. |
| 78 | const EL_H_SP: i64 = 3 // zone stack depth |
| 79 | const EL_H_LASTF: i64 = 4 // record index of the most recent FRAME, or -1 |
| 80 | const EL_H_MAXSP: i64 = 5 // high-water stack depth |
| 81 | const EL_H_ERRMONO: i64 = 6 // timestamps that went backwards |
| 82 | const EL_H_ERROVF: i64 = 7 // zone stack overflows |
| 83 | const EL_H_ERRUND: i64 = 8 // zone END with no matching BEGIN |
| 84 | const EL_H_NFRAME: i64 = 9 // FRAME records pushed |
| 85 | const EL_H_MAGIC: i64 = 10 |
| 86 | const EL_H_RESV: i64 = 11 |
| 87 | const EL_H: i64 = 12 |
| 89 | const EL_STACK_MAX: i64 = 64 // nesting depth; an overflow is COUNTED and refused, never wrapped |
| 90 | const EL_REC_BASE: i64 = EL_H + EL_STACK_MAX |
| 91 | const EL_MAGIC: i64 = 3126741 // witness that a pointer is really a store |
| 203 | const EL_AGG_CALLS: i64 = 0 |
| 204 | const EL_AGG_INCL: i64 = 1 |
| 205 | const EL_AGG_SELF: i64 = 2 |
| 206 | const EL_AGG_MAX: i64 = 3 |
| 207 | const EL_AGG_OPEN: i64 = 4 |
| 208 | const EL_AGG_SLOTS: i64 = 5 |
| 275 | const EL_MEM_NALLOC: i64 = 0 |
| 276 | const EL_MEM_NFREE: i64 = 1 |
| 277 | const EL_MEM_BALLOC: i64 = 2 |
| 278 | const EL_MEM_BFREE: i64 = 3 |
| 279 | const EL_MEM_ORPHAN: i64 = 4 |
| 280 | const EL_MEM_SLOTS: i64 = 5 |
| 375 | const EL_FS_FRAMES: i64 = 0 |
| 376 | const EL_FS_SPAN: i64 = 1 |
| 377 | const EL_FS_AVGFPS: i64 = 2 // x1000 |
| 378 | const EL_FS_WORST: i64 = 3 // us |
| 379 | const EL_FS_MEDIAN: i64 = 4 // us |
| 380 | const EL_FS_LOW1: i64 = 5 // x1000 fps |
| 381 | const EL_FS_LOW01: i64 = 6 // x1000 fps |
| 382 | const EL_FS_STUTTER: i64 = 7 |
| 383 | const EL_FS_OPEN: i64 = 8 // frames with no successor, excluded from every statistic |
| 384 | const EL_FS_SLOTS: i64 = 9 |
| 386 | const EL_FPS_SCALE: i64 = 1000000000 // us -> fps x1000 |
| 387 | const EL_LOW1_PERMIL: i64 = 10 // worst 1 percent |
| 388 | const EL_LOW01_PERMIL: i64 = 1 // worst 0.1 percent |
| 389 | const EL_STUTTER_NUM_DEFAULT: i64 = 2 // > 2x median = a stutter (named, and overridable) |
| 390 | const EL_STUTTER_DEN_DEFAULT: i64 = 1 |
| 493 | const EL_GQ_SLICES: i64 = 0 |
| 494 | const EL_GQ_BUSY: i64 = 1 |
| 495 | const EL_GQ_WAIT: i64 = 2 |
| 496 | const EL_GQ_WORST: i64 = 3 |
| 497 | const EL_GQ_SLOTS: i64 = 4 |
| 526 | const EL_BOUND_UNKNOWN: i64 = 3 |
| 527 | const EL_BOUND_GPU: i64 = 1 |
| 528 | const EL_BOUND_CPU: i64 = 2 |
| 529 | const EL_BOUND_BOTH: i64 = 4 |
| 530 | const EL_BOUND_IDLE: i64 = 5 |
| 531 | const EL_OCC_HI_DEFAULT: i64 = 900 // permil of the frame a unit must occupy to be called the bound |
| 533 | const EL_BV_DUR: i64 = 0 |
| 534 | const EL_BV_GPUOCC: i64 = 1 // permil |
| 535 | const EL_BV_CPUOCC: i64 = 2 // permil |
| 536 | const EL_BV_GPUUS: i64 = 3 |
| 537 | const EL_BV_CPUUS: i64 = 4 |
| 538 | const EL_BV_SLOTS: i64 = 5 |
| 631 | const EL_HASH_MUL: i64 = 131 |
| 632 | const EL_HASH_MOD: i64 = 1000000007 |
| 682 | const EL_DIFF_SAME: i64 = 0 |
| 683 | const EL_DIFF_DIVERGENT: i64 = 1 |
| 684 | const EL_DIFF_UNMEASURABLE:i64 = 3 |
| 685 | const EL_DF_ORD: i64 = 0 |
| 686 | const EL_DF_FIELD: i64 = 1 |
| 687 | const EL_DF_AVAL: i64 = 2 |
| 688 | const EL_DF_BVAL: i64 = 3 |
| 689 | const EL_DF_ACNT: i64 = 4 |
| 690 | const EL_DF_BCNT: i64 = 5 |
| 691 | const EL_DF_SLOTS: i64 = 6 |
| 693 | const EL_DFF_COUNT: i64 = 1 |
| 694 | const EL_DFF_PIPELINE: i64 = 2 |
| 695 | const EL_DFF_VERTS: i64 = 3 |
| 696 | const EL_DFF_STATE: i64 = 4 |
| 697 | const EL_DFF_NAME: i64 = 5 |
| 774 | const EL_FA_DUR: i64 = 0 |
| 775 | const EL_FA_DRAWS: i64 = 1 |
| 776 | const EL_FA_GPUUS: i64 = 2 |
| 777 | const EL_FA_CPUUS: i64 = 3 |
| 778 | const EL_FA_LOCKUS: i64 = 4 |
| 779 | const EL_FA_ALLOCB: i64 = 5 |
| 780 | const EL_FA_EVENTS: i64 = 6 |
| 781 | const EL_FA_HOTNAME:i64 = 7 |
| 782 | const EL_FA_SLOTS: i64 = 8 |
| 849 | const EL_CAP_MAGIC: *u8 = "NXEL1" |
| 850 | const EL_CAP_TRAILER: *u8 = "NXEL1END" |
| 851 | const EL_SP: i64 = 32 |
| 852 | const EL_NL: i64 = 10 |
| 853 | const EL_CR: i64 = 13 |
| 854 | const EL_HTAB: i64 = 9 |
| 855 | const EL_MINUS_CH: i64 = 45 |
| 856 | const EL_D0: i64 = 48 |
| 857 | const EL_D9: i64 = 57 |
| 858 | const EL_DECBASE: i64 = 10 |
| 862 | const EL_CAP_LINE_MAX: i64 = 200 |
| 863 | const EL_CAP_EDGE_MAX: i64 = 128 |
| 865 | const EL_CAP_MIN_LINE: i64 = 16 |
| 868 | const EL_CP_OK: i64 = 0 |
| 869 | const EL_CP_NOFILE: i64 = 1 |
| 870 | const EL_CP_BAD_MAGIC: i64 = 2 |
| 871 | const EL_CP_BAD_HEADER: i64 = 3 |
| 872 | const EL_CP_TOO_BIG: i64 = 4 |
| 873 | const EL_CP_SHORT: i64 = 5 |
| 874 | const EL_CP_NO_TRAILER: i64 = 6 |
| 875 | const EL_CP_TRAILER_MISMATCH: i64 = 7 |
| 876 | const EL_CP_NOMEM: i64 = 8 |
| 887 | const EL_CP_CHECKSUM: i64 = 9 |
| 893 | const EL_WCK_MUL: i64 = 1000003 |
| 894 | const EL_WCK_MOD: i64 = 2147483647 |
| 1157 | const EL_Q_UNKNOWN: i64 = 0 |
| 1158 | const EL_Q_NATIVE: i64 = 1 |
| 1159 | const EL_Q_GOVERNOR: i64 = 2 |
| 1160 | const EL_Q_RECORD: i64 = 3 |
| 1161 | const EL_Q_EXPLICIT: i64 = 4 |
| 1162 | const EL_Q_GEOMETRY: i64 = 5 |
| 1163 | const EL_Q_FULL_PERMIL: i64 = 1000 |
| 1165 | const EL_OV_FRAMES: i64 = 0 |
| 1166 | const EL_OV_AVGFPS: i64 = 1 |
| 1167 | const EL_OV_WORST: i64 = 2 |
| 1168 | const EL_OV_MEDIAN: i64 = 3 |
| 1169 | const EL_OV_LOW1: i64 = 4 |
| 1170 | const EL_OV_STUTTER: i64 = 5 |
| 1171 | const EL_OV_OPEN: i64 = 6 |
| 1172 | const EL_OV_DROPPED: i64 = 7 |
| 1173 | const EL_OV_DRAWS: i64 = 8 |
| 1174 | const EL_OV_REDUNDANT: i64 = 9 |
| 1175 | const EL_OV_BUDGET: i64 = 10 |
| 1176 | const EL_OV_HEADROOM: i64 = 11 |
| 1177 | const EL_OV_QPERMIL: i64 = 12 |
| 1178 | const EL_OV_QREASON: i64 = 13 |
| 1179 | const EL_OV_TRIS: i64 = 14 |
| 1180 | const EL_OV_SLOTS: i64 = 15 |
| 1212 | const EL_OV_MAGIC: *u8 = "NXOV1" |
| 1213 | const EL_OV_TRAILER: *u8 = "NXOV1END" |
| 1215 | const EL_OV_TEXT_MAX: i64 = 1024 |
functions
| 93 | func el_new(cap: i64) -> *i64 |
| 115 | func el_ok(st: *i64) -> i64 |
| 120 | func el_count(st: *i64) -> i64 { return st[EL_H_N] } |
| 121 | func el_dropped(st: *i64) -> i64 { return st[EL_H_DROP] } |
| 124 | func el_complete(st: *i64) -> i64 { if st[EL_H_DROP] == 0 { return 1 } return 0 } |
| 125 | func el_errors(st: *i64) -> i64 { return st[EL_H_ERRMONO] + st[EL_H_ERROVF] + st[EL_H_ERRUND] } |
| 127 | func el_get(st: *i64, i: i64, f: i64) -> i64 { return st[EL_REC_BASE + i * EL_REC + f] } |
| 128 | func el_set(st: *i64, i: i64, f: i64, v: i64) -> i64 { st[EL_REC_BASE + i * EL_REC + f] = v; return 0 } |
| 131 | func el_push(st: *i64, kind: i64, ts: i64, dur: i64, tid: i64, name: i64, a: i64, b: i64, c: i64) -> i64 |
| 154 | func el_zone_begin(st: *i64, ts: i64, tid: i64, name: i64) -> i64 |
| 169 | func el_zone_end(st: *i64, ts: i64) -> i64 |
| 194 | func el_zone_open(st: *i64) -> i64 { return st[EL_H_SP] } called by 1: main |
| 195 | func el_zone_self(st: *i64, idx: i64) -> i64 |
| 209 | func el_zone_agg(st: *i64, name: i64, out: *i64) -> i64 |
| 234 | func el_zone_hottest(st: *i64, out: *i64) -> i64 |
| 260 | func el_alloc(st: *i64, ts: i64, tid: i64, name: i64, bytes: i64, addr: i64) -> i64 |
| 263 | func el_free(st: *i64, ts: i64, tid: i64, addr: i64) -> i64 |
| 266 | func el_lock_wait(st: *i64, ts: i64, dur: i64, tid: i64, name: i64, owner: i64) -> i64 |
| 281 | func el_mem_stats(st: *i64, out: *i64) -> i64 |
| 318 | func el_frame_mark(st: *i64, ts: i64) -> i64 |
| 334 | func el_frame_rec(st: *i64, ord: i64) -> i64 |
| 349 | func el_sort_desc(a: *i64, n: i64) -> i64 called by 1: el_frame_stats |
| 392 | func el_low_mean_fps(a: *i64, n: i64, permil: i64) -> i64 called by 1: el_frame_stats |
| 405 | func el_frame_stats(st: *i64, mult_num: i64, mult_den: i64, out: *i64) -> i64 called by 4: eld_reportmainmainel_overlay_stats calls 5: el_getsys_mmapel_sort_descel_low_mean_fpssys_munmap |
| 460 | func el_fps_rolling(st: *i64, now_ms: i64) -> i64 |
| 476 | func el_budget_verdict(frame_us: i64, target_fps: i64, out: *i64) -> i64 |
| 484 | func el_gpu_slice(st: *i64, submit_ts: i64, start_ts: i64, dur: i64, queue: i64, name: i64) -> i64 |
| 487 | func el_vsync(st: *i64, ts: i64) -> i64 { return el_push(st, EL_K_VSYNC, ts, 0, 0, 0, 0, 0, 0) } calls 1: el_push |
| 498 | func el_gpu_stats(st: *i64, queue: i64, out: *i64) -> i64 |
| 540 | func el_bound_verdict(st: *i64, ord: i64, hi_permil: i64, out: *i64) -> i64 |
| 595 | func el_zone_is_root(st: *i64, idx: i64) -> i64 |
| 625 | func el_draw(st: *i64, ts: i64, tid: i64, name: i64, pipeline: i64, verts: i64, state_hash: i64) -> i64 |
| 633 | func el_state_hash(vals: *i64, n: i64) -> i64 called by 1: main |
| 643 | func el_draw_count(st: *i64) -> i64 |
| 656 | func el_draw_redundant(st: *i64) -> i64 |
| 699 | func el_draw_nth(st: *i64, ord: i64) -> i64 |
| 716 | func el_capture_diff(a: *i64, b: *i64, out: *i64) -> i64 |
| 784 | func el_frame_attr(st: *i64, ord: i64, out: *i64) -> i64 |
| 899 | func el_wire_ck(st: *i64, n: i64, nframe: i64, drop: i64) -> i64 |
| 918 | func el_cat_lit(d: *u8, o: i64, s: *u8) -> i64 |
| 927 | func el_capture_bytes(st: *i64) -> i64 |
| 932 | func el_capture_serialize(st: *i64, buf: *u8, cap: i64) -> i64 |
| 964 | func el_is_ws(c: i64) -> i64 called by 1: el_scan_ws |
| 972 | func el_scan_ws(buf: *u8, len: i64, pos: i64) -> i64 |
| 986 | func el_scan_i64(buf: *u8, len: i64, pos: i64, out: *i64) -> i64 |
| 1015 | func el_scan_lit(buf: *u8, len: i64, pos: i64, lit: *u8) -> i64 |
| 1031 | func el_capture_parse(buf: *u8, len: i64, err: *i64) -> *i64 |
| 1182 | func el_overlay_stats(st: *i64, target_fps: i64, q_permil: i64, q_reason: i64, tris: i64, out: *i64) -> i64 called by 2: mainel_overlay_emit calls 8: el_oksys_mmapel_frame_statsel_droppedel_draw_countel_draw_redundant+2 |
| 1217 | func el_ov_row(buf: *u8, p0: i64, label: *u8, v: i64) -> i64 |
| 1228 | func el_overlay_emit(st: *i64, target_fps: i64, q_permil: i64, q_reason: i64, tris: i64, buf: *u8, cap: i64) -> i64 |