code wiki / _hdl_build / nx_js_rt_memprobe.nx
nx_js_rt_memprobe.nx source
↩ module page · 22 lines · 1583 B
1// measure the pool allocation of a REDUCED RayTrace render (20x20, checkNumber assert disabled) to quantify
2// the GC target: total pool MB + alloc count. expect_exit: 0 license_tier: ORIGINAL
3import "nx_js_vm.nx"
4const K_MAGIC_262144: i64 = 262144
5func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
6func nn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var q: i64=k-1; var x: i64=0; while q>=0 { o[x]=t[q]; x=x+1; q=q-1 } sys_write(1,o,x); return 0 }
7func main(argc: i64, argv: *i64) -> i64 {
8 let fd: i64 = sys_openat_rd("knowledge/octane/jsprobes.js\x00" as *u8)
9 if fd < 0 { w("RED: no jsprobes.js\n" as *u8); return 1 }
10 let buf: *u8 = sys_mmap(K_MAGIC_262144)
11 var total: i64 = 0
12 var done: i64 = 0
13 while done == 0 { let n: i64 = sys_read(fd, ((buf as i64) + total) as *u8, K_MAGIC_262144 - total); if n <= 0 { done = 1 } else { total = total + n } }
14 sys_close(fd)
15 buf[total] = 0 as u8
16 let out: *i64 = sys_mmap(16) as *i64
17 let rc: i64 = compile_run(buf, out)
18 w("rc=" as *u8); nn(rc); w(" result=" as *u8)
19 if out[0] == VAL_STR { sys_write(1, ev_str_bytes((out[1]) as *i64), ev_str_len((out[1]) as *i64)) } else { w("tag" as *u8); nn(out[0]) }
20 w("\n POOL total=" as *u8); nn(nx_pool_total_mb()); w("MB allocs=" as *u8); nn(nx_pool_alloc_count()); w("\n" as *u8)
21 return 0
22}