code wiki / _hdl_build / nx_transient_pulse.nx

nx_transient_pulse.nx source

↩ module page · 70 lines · 4246 B

1// nx_transient_pulse.nx -- the CONTINUOUS heartbeat for S-class transient monitoring. Each cycle it forks the 2// transient SWEEP across a data-driven target list (knowledge/registry/transient_targets.list -- rule #11, NOT 3// hardcoded, NOT tsv: one elf-path per line, # comments skipped), so the ecosystem accounts for every 4// component's flakiness AUTOMATICALLY over time, not just when a human runs it. Each cycle's results are 5// durably recorded by the sweep (seg-store). Sleeps `interval_sec` between cycles. 6// usage: nx_transient_pulse <interval_sec> <cycles> [runs_per=5] [timeout_ms=8000] 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9const TP_MAGIC_8000: i64 = 8000 10const TP_MAGIC_65536: i64 = 65536 11 12const TP_CONFIG: *u8 = "knowledge/registry/transient_targets.list" 13const TP_SWEEP: *u8 = "_offc/nx_transient_sweep.elf" 14 15func tp_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 16func tp_wn(v: i64) -> i64 { var m: i64=v; var k: i64=0; if m<0{tp_w("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0{o[w]=t[q];w=w+1;q=q-1} sys_write(1,o,w); return 0 } 17func tp_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ if s[i]>=(48 as u8){ if s[i]<=(57 as u8){ v=v*10+((s[i] as i64)-48) } } i=i+1 } return v } 18func tp_itoa(v: i64, out: *u8) -> i64 { if v==0 { out[0]=48 as u8; out[1]=0 as u8; return 1 } let t: *u8=sys_mmap(24); var m: i64=v; var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{out[i]=t[k-1-i];i=i+1} out[k]=0 as u8; return k } 19func tp_read(path: *u8, buf: *u8, cap: i64) -> i64 { 20 let fd: i64=sys_openat_rd(path); if fd<0 {return 0-1} 21 var off: i64=0; var go: i64=1 22 while go==1 { if off>=cap {go=0} else { let r: i64=sys_read(fd, buf+off, cap-off); if r<=0 {go=0} else {off=off+r} } } 23 sys_close(fd); return off 24} 25 26func main(argc: i64, argv: *i64) -> i64 { 27 if argc < 3 { tp_w("usage: nx_transient_pulse <interval_sec> <cycles> [runs_per] [timeout_ms]\n" as *u8); return 2 } 28 let interval: i64 = tp_atoi(argv[1] as *u8) 29 let cycles: i64 = tp_atoi(argv[2] as *u8) 30 var runs: i64 = 5; if argc >= 4 { runs = tp_atoi(argv[3] as *u8) } 31 var timeout: i64 = TP_MAGIC_8000; if argc >= 5 { timeout = tp_atoi(argv[4] as *u8) } 32 33 let cbuf: *u8 = sys_mmap(TP_MAGIC_65536); let n: i64 = tp_read(TP_CONFIG, cbuf, TP_MAGIC_65536) 34 if n <= 0 { tp_w("transient-pulse: no targets config at " as *u8); tp_w(TP_CONFIG); tp_w("\n" as *u8); return 1 } 35 let paths: *i64 = sys_mmap(8*256) as *i64; var np: i64=0 36 var ls: i64=0; var i: i64=0 37 while i <= n { 38 var nl: i64=0; if i>=n {nl=1} else { if cbuf[i]==(10 as u8){nl=1} } 39 if nl==1 { 40 if i > ls { 41 cbuf[i]=0 as u8 42 let p: *u8 = ((cbuf as i64)+ls) as *u8 43 if p[0] != (35 as u8) { if np<256 { paths[np]=p as i64; np=np+1 } } 44 } 45 ls = i+1 46 } 47 i = i+1 48 } 49 if np == 0 { tp_w("transient-pulse: 0 targets in config\n" as *u8); return 1 } 50 51 let runs_s: *u8 = sys_mmap(24); tp_itoa(runs, runs_s) 52 let to_s: *u8 = sys_mmap(24); tp_itoa(timeout, to_s) 53 let av: *i64 = sys_mmap(8*(np+6)) as *i64 54 av[0]=TP_SWEEP as i64; av[1]=runs_s as i64; av[2]=to_s as i64 55 var a: i64=3; var j: i64=0; while j<np { av[a]=paths[j]; a=a+1; j=j+1 } av[a]=0 56 let ev: *i64 = sys_mmap(16) as *i64; ev[0]="PATH=/usr/bin:/bin" as *u8 as i64; ev[1]=0 57 58 tp_w("=== TRANSIENT-PULSE start: " as *u8); tp_wn(np); tp_w(" targets, " as *u8); tp_wn(cycles); tp_w(" cycles, every " as *u8); tp_wn(interval); tp_w("s ===\n" as *u8) 59 var c: i64=0 60 while c < cycles { 61 tp_w("--- cycle " as *u8); tp_wn(c+1); tp_w("/" as *u8); tp_wn(cycles); tp_w(" ---\n" as *u8) 62 let pid: i64 = sys_fork() 63 if pid == 0 { sys_execve(TP_SWEEP, av, ev); sys_exit(127) } 64 let st: *i64 = sys_mmap(16) as *i64; sys_wait4(pid, st, 0) 65 c = c + 1 66 if c < cycles { sys_sleep_ms(interval * 1000) } 67 } 68 tp_w("=== TRANSIENT-PULSE done (" as *u8); tp_wn(cycles); tp_w(" cycles) ===\n" as *u8) 69 return 0 70}