code wiki / (root) / nx_enginelab_lib.nx

nx_enginelab_lib.nx

buildroot/runtime/nx_enginelab_lib.nx

56204 B1253 linesdepth 3pulls 5 transitivereach 6 importersview sourcekind librarytopic enginelab
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_fpsmeter.nx nx_frame_budget.nx nx_itoa_lib.nx nx_enginelab_lib.nx nx_enginelab.nx nx_enginelab_analysis.nx nx_enginelab_analysis_gate.nx nx_enginelab_gate.nx nx_enginelab_golden.nx nx_enginelab_store.nx

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

49const EL_I64: i64 = 8 // bytes per i64
50const EL_REC: i64 = 8 // i64 per record
52const EL_F_KIND: i64 = 0
53const EL_F_TS: i64 = 1 // monotonic microseconds, caller-supplied
54const EL_F_DUR: i64 = 2 // filled at close; EL_DUR_OPEN while a scope is open
55const EL_F_TID: i64 = 3 // CPU thread id, or GPU queue id for EL_K_GPU
56const EL_F_NAME: i64 = 4 // interned name id -- an id, never a string: no allocation in a hot loop
57const EL_F_A: i64 = 5 // DRAW: pipeline id ALLOC: bytes GPU: submit ts
58const EL_F_B: i64 = 6 // DRAW: vertex count ALLOC: address LOCK: owner tid
59const EL_F_C: i64 = 7 // DRAW: state hash ZONE: child total us FRAME: frame ordinal
61const EL_DUR_OPEN: i64 = -1 // a scope that has begun and not ended
64const EL_K_FRAME: i64 = 1
65const EL_K_ZONE: i64 = 2
66const EL_K_GPU: i64 = 3
67const EL_K_DRAW: i64 = 4
68const EL_K_ALLOC: i64 = 5
69const EL_K_FREE: i64 = 6
70const EL_K_LOCK: i64 = 7
71const EL_K_VSYNC: i64 = 8
75const EL_H_CAP: i64 = 0
76const EL_H_N: i64 = 1
77const EL_H_DROP: i64 = 2 // records REFUSED because the store was full. Never silent.
78const EL_H_SP: i64 = 3 // zone stack depth
79const EL_H_LASTF: i64 = 4 // record index of the most recent FRAME, or -1
80const EL_H_MAXSP: i64 = 5 // high-water stack depth
81const EL_H_ERRMONO: i64 = 6 // timestamps that went backwards
82const EL_H_ERROVF: i64 = 7 // zone stack overflows
83const EL_H_ERRUND: i64 = 8 // zone END with no matching BEGIN
84const EL_H_NFRAME: i64 = 9 // FRAME records pushed
85const EL_H_MAGIC: i64 = 10
86const EL_H_RESV: i64 = 11
87const EL_H: i64 = 12
89const EL_STACK_MAX: i64 = 64 // nesting depth; an overflow is COUNTED and refused, never wrapped
90const EL_REC_BASE: i64 = EL_H + EL_STACK_MAX
91const EL_MAGIC: i64 = 3126741 // witness that a pointer is really a store
203const EL_AGG_CALLS: i64 = 0
204const EL_AGG_INCL: i64 = 1
205const EL_AGG_SELF: i64 = 2
206const EL_AGG_MAX: i64 = 3
207const EL_AGG_OPEN: i64 = 4
208const EL_AGG_SLOTS: i64 = 5
275const EL_MEM_NALLOC: i64 = 0
276const EL_MEM_NFREE: i64 = 1
277const EL_MEM_BALLOC: i64 = 2
278const EL_MEM_BFREE: i64 = 3
279const EL_MEM_ORPHAN: i64 = 4
280const EL_MEM_SLOTS: i64 = 5
375const EL_FS_FRAMES: i64 = 0
376const EL_FS_SPAN: i64 = 1
377const EL_FS_AVGFPS: i64 = 2 // x1000
378const EL_FS_WORST: i64 = 3 // us
379const EL_FS_MEDIAN: i64 = 4 // us
380const EL_FS_LOW1: i64 = 5 // x1000 fps
381const EL_FS_LOW01: i64 = 6 // x1000 fps
382const EL_FS_STUTTER: i64 = 7
383const EL_FS_OPEN: i64 = 8 // frames with no successor, excluded from every statistic
384const EL_FS_SLOTS: i64 = 9
386const EL_FPS_SCALE: i64 = 1000000000 // us -> fps x1000
387const EL_LOW1_PERMIL: i64 = 10 // worst 1 percent
388const EL_LOW01_PERMIL: i64 = 1 // worst 0.1 percent
389const EL_STUTTER_NUM_DEFAULT: i64 = 2 // > 2x median = a stutter (named, and overridable)
390const EL_STUTTER_DEN_DEFAULT: i64 = 1
493const EL_GQ_SLICES: i64 = 0
494const EL_GQ_BUSY: i64 = 1
495const EL_GQ_WAIT: i64 = 2
496const EL_GQ_WORST: i64 = 3
497const EL_GQ_SLOTS: i64 = 4
526const EL_BOUND_UNKNOWN: i64 = 3
527const EL_BOUND_GPU: i64 = 1
528const EL_BOUND_CPU: i64 = 2
529const EL_BOUND_BOTH: i64 = 4
530const EL_BOUND_IDLE: i64 = 5
531const EL_OCC_HI_DEFAULT: i64 = 900 // permil of the frame a unit must occupy to be called the bound
533const EL_BV_DUR: i64 = 0
534const EL_BV_GPUOCC: i64 = 1 // permil
535const EL_BV_CPUOCC: i64 = 2 // permil
536const EL_BV_GPUUS: i64 = 3
537const EL_BV_CPUUS: i64 = 4
538const EL_BV_SLOTS: i64 = 5
631const EL_HASH_MUL: i64 = 131
632const EL_HASH_MOD: i64 = 1000000007
682const EL_DIFF_SAME: i64 = 0
683const EL_DIFF_DIVERGENT: i64 = 1
684const EL_DIFF_UNMEASURABLE:i64 = 3
685const EL_DF_ORD: i64 = 0
686const EL_DF_FIELD: i64 = 1
687const EL_DF_AVAL: i64 = 2
688const EL_DF_BVAL: i64 = 3
689const EL_DF_ACNT: i64 = 4
690const EL_DF_BCNT: i64 = 5
691const EL_DF_SLOTS: i64 = 6
693const EL_DFF_COUNT: i64 = 1
694const EL_DFF_PIPELINE: i64 = 2
695const EL_DFF_VERTS: i64 = 3
696const EL_DFF_STATE: i64 = 4
697const EL_DFF_NAME: i64 = 5
774const EL_FA_DUR: i64 = 0
775const EL_FA_DRAWS: i64 = 1
776const EL_FA_GPUUS: i64 = 2
777const EL_FA_CPUUS: i64 = 3
778const EL_FA_LOCKUS: i64 = 4
779const EL_FA_ALLOCB: i64 = 5
780const EL_FA_EVENTS: i64 = 6
781const EL_FA_HOTNAME:i64 = 7
782const EL_FA_SLOTS: i64 = 8
849const EL_CAP_MAGIC: *u8 = "NXEL1"
850const EL_CAP_TRAILER: *u8 = "NXEL1END"
851const EL_SP: i64 = 32
852const EL_NL: i64 = 10
853const EL_CR: i64 = 13
854const EL_HTAB: i64 = 9
855const EL_MINUS_CH: i64 = 45
856const EL_D0: i64 = 48
857const EL_D9: i64 = 57
858const EL_DECBASE: i64 = 10
862const EL_CAP_LINE_MAX: i64 = 200
863const EL_CAP_EDGE_MAX: i64 = 128
865const EL_CAP_MIN_LINE: i64 = 16
868const EL_CP_OK: i64 = 0
869const EL_CP_NOFILE: i64 = 1
870const EL_CP_BAD_MAGIC: i64 = 2
871const EL_CP_BAD_HEADER: i64 = 3
872const EL_CP_TOO_BIG: i64 = 4
873const EL_CP_SHORT: i64 = 5
874const EL_CP_NO_TRAILER: i64 = 6
875const EL_CP_TRAILER_MISMATCH: i64 = 7
876const EL_CP_NOMEM: i64 = 8
887const EL_CP_CHECKSUM: i64 = 9
893const EL_WCK_MUL: i64 = 1000003
894const EL_WCK_MOD: i64 = 2147483647
1157const EL_Q_UNKNOWN: i64 = 0
1158const EL_Q_NATIVE: i64 = 1
1159const EL_Q_GOVERNOR: i64 = 2
1160const EL_Q_RECORD: i64 = 3
1161const EL_Q_EXPLICIT: i64 = 4
1162const EL_Q_GEOMETRY: i64 = 5
1163const EL_Q_FULL_PERMIL: i64 = 1000
1165const EL_OV_FRAMES: i64 = 0
1166const EL_OV_AVGFPS: i64 = 1
1167const EL_OV_WORST: i64 = 2
1168const EL_OV_MEDIAN: i64 = 3
1169const EL_OV_LOW1: i64 = 4
1170const EL_OV_STUTTER: i64 = 5
1171const EL_OV_OPEN: i64 = 6
1172const EL_OV_DROPPED: i64 = 7
1173const EL_OV_DRAWS: i64 = 8
1174const EL_OV_REDUNDANT: i64 = 9
1175const EL_OV_BUDGET: i64 = 10
1176const EL_OV_HEADROOM: i64 = 11
1177const EL_OV_QPERMIL: i64 = 12
1178const EL_OV_QREASON: i64 = 13
1179const EL_OV_TRIS: i64 = 14
1180const EL_OV_SLOTS: i64 = 15
1212const EL_OV_MAGIC: *u8 = "NXOV1"
1213const EL_OV_TRAILER: *u8 = "NXOV1END"
1215const EL_OV_TEXT_MAX: i64 = 1024

functions

93func el_new(cap: i64) -> *i64
115func el_ok(st: *i64) -> i64
120func el_count(st: *i64) -> i64 { return st[EL_H_N] }
called by 3: eld_reportmainmain
121func el_dropped(st: *i64) -> i64 { return st[EL_H_DROP] }
124func el_complete(st: *i64) -> i64 { if st[EL_H_DROP] == 0 { return 1 } return 0 }
called by 3: eld_reportmainmain
125func el_errors(st: *i64) -> i64 { return st[EL_H_ERRMONO] + st[EL_H_ERROVF] + st[EL_H_ERRUND] }
called by 2: eld_reportmain
127func el_get(st: *i64, i: i64, f: i64) -> i64 { return st[EL_REC_BASE + i * EL_REC + f] }
128func el_set(st: *i64, i: i64, f: i64, v: i64) -> i64 { st[EL_REC_BASE + i * EL_REC + f] = v; return 0 }
131func el_push(st: *i64, kind: i64, ts: i64, dur: i64, tid: i64, name: i64, a: i64, b: i64, c: i64) -> i64
154func el_zone_begin(st: *i64, ts: i64, tid: i64, name: i64) -> i64
called by 3: eld_runag_treemain calls 1: el_push
169func el_zone_end(st: *i64, ts: i64) -> i64
called by 3: eld_runag_treemain calls 2: el_getel_set
194func el_zone_open(st: *i64) -> i64 { return st[EL_H_SP] }
called by 1: main
195func el_zone_self(st: *i64, idx: i64) -> i64
called by 1: main calls 1: el_get
209func el_zone_agg(st: *i64, name: i64, out: *i64) -> i64
called by 2: eld_zone_lineel_zone_hottest calls 1: el_get
234func el_zone_hottest(st: *i64, out: *i64) -> i64
260func el_alloc(st: *i64, ts: i64, tid: i64, name: i64, bytes: i64, addr: i64) -> i64
called by 2: eld_runmain calls 1: el_push
263func el_free(st: *i64, ts: i64, tid: i64, addr: i64) -> i64
called by 1: main calls 1: el_push
266func el_lock_wait(st: *i64, ts: i64, dur: i64, tid: i64, name: i64, owner: i64) -> i64
called by 1: main calls 1: el_push
281func el_mem_stats(st: *i64, out: *i64) -> i64
called by 2: eld_reportmain calls 1: el_get
318func el_frame_mark(st: *i64, ts: i64) -> i64
334func el_frame_rec(st: *i64, ord: i64) -> i64
349func el_sort_desc(a: *i64, n: i64) -> i64
called by 1: el_frame_stats
392func el_low_mean_fps(a: *i64, n: i64, permil: i64) -> i64
called by 1: el_frame_stats
405func el_frame_stats(st: *i64, mult_num: i64, mult_den: i64, out: *i64) -> i64
460func el_fps_rolling(st: *i64, now_ms: i64) -> i64
476func el_budget_verdict(frame_us: i64, target_fps: i64, out: *i64) -> i64
484func el_gpu_slice(st: *i64, submit_ts: i64, start_ts: i64, dur: i64, queue: i64, name: i64) -> i64
called by 1: main calls 1: el_push
487func 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
498func el_gpu_stats(st: *i64, queue: i64, out: *i64) -> i64
called by 1: main calls 1: el_get
540func el_bound_verdict(st: *i64, ord: i64, hi_permil: i64, out: *i64) -> i64
595func el_zone_is_root(st: *i64, idx: i64) -> i64
625func el_draw(st: *i64, ts: i64, tid: i64, name: i64, pipeline: i64, verts: i64, state_hash: i64) -> i64
633func el_state_hash(vals: *i64, n: i64) -> i64
called by 1: main
643func el_draw_count(st: *i64) -> i64
656func el_draw_redundant(st: *i64) -> i64
called by 2: mainel_overlay_stats calls 1: el_get
699func el_draw_nth(st: *i64, ord: i64) -> i64
716func el_capture_diff(a: *i64, b: *i64, out: *i64) -> i64
called by 1: main calls 3: el_draw_countel_draw_nthel_get
784func el_frame_attr(st: *i64, ord: i64, out: *i64) -> i64
899func el_wire_ck(st: *i64, n: i64, nframe: i64, drop: i64) -> i64
918func el_cat_lit(d: *u8, o: i64, s: *u8) -> i64
927func el_capture_bytes(st: *i64) -> i64
called by 2: mainel_capture_serialize calls 1: el_ok
932func el_capture_serialize(st: *i64, buf: *u8, cap: i64) -> i64
964func el_is_ws(c: i64) -> i64
called by 1: el_scan_ws
972func el_scan_ws(buf: *u8, len: i64, pos: i64) -> i64
called by 2: el_scan_i64el_scan_lit calls 1: el_is_ws
986func el_scan_i64(buf: *u8, len: i64, pos: i64, out: *i64) -> i64
called by 1: el_capture_parse calls 1: el_scan_ws
1015func el_scan_lit(buf: *u8, len: i64, pos: i64, lit: *u8) -> i64
called by 1: el_capture_parse calls 1: el_scan_ws
1031func el_capture_parse(buf: *u8, len: i64, err: *i64) -> *i64
1182func el_overlay_stats(st: *i64, target_fps: i64, q_permil: i64, q_reason: i64, tris: i64, out: *i64) -> i64
1217func el_ov_row(buf: *u8, p0: i64, label: *u8, v: i64) -> i64
called by 1: el_overlay_emit calls 2: el_cat_litnxi_buf
1228func el_overlay_emit(st: *i64, target_fps: i64, q_permil: i64, q_reason: i64, tris: i64, buf: *u8, cap: i64) -> i64