interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / readings-window / main.om

125 lines · 2396 bytes Raw Blame History
1note readings-window CLI: reads TSV telemetry samples from stdin, emits window stats JSON or text.
2note Compose: si/directives/om2.om + apps/readings-window/lib.om + apps/readings-window/main.om
3
4text rw_cli_flag_text "--text"
5text rw_cli_err_parse "readings-window: malformed telemetry TSV line\n"
6text rw_cli_err_ingest "readings-window: sample refused (monotonicity or bounds violation)\n"
7text rw_cli_err_empty "readings-window: no telemetry samples provided\n"
8
9fn rw_write_all fd int buf view uchar * n ulong to bool
10done = ulong 0
11while lt done n bound 65536
12k = write fd buf done sub n done
13if le k 0
14ret false
15end
16done = add done ulong k
17end
18ret true
19end
20
21fn rw_read_stdin dst edit uchar * to long
22got = ulong 0
23cap = len dst
24while lt got cap bound 65536
25k = read 0 dst got sub cap got
26if lt k 0
27ret -1
28end
29if eq k 0
30break
31end
32got = add got ulong k
33end
34ret long got
35end
36
37fn rw_want_text to bool
38if lt argcnt 2
39ret false
40end
41a1 = new uchar 64 0
42n1 = argread 1 a1 0 64
43if le n1 0
44ret false
45end
46ret rw_eq_bytes part a1 0 ulong n1 rw_cli_flag_text
47end
48
49fn main to int
50inbuf = new uchar 16384 0
51nread = rw_read_stdin inbuf
52if le nread 0
53w = rw_write_all 2 rw_cli_err_empty len rw_cli_err_empty
54if not w
55ret 2
56end
57ret 1
58end
59ring = new RwRing 0 0 0 0 0
60rbuf = new ulong 512 0
61rw_ring_init ring
62sample = new RwSample 0 0 0 0 0 0 0
63cur = ulong 0
64total = ulong nread
65while lt cur total bound 16384
66ls = cur
67while lt cur total bound 16384
68if eq get inbuf cur 10
69cur = add cur 1
70break
71end
72cur = add cur 1
73end
74ll = sub cur ls
75if eq ll 0
76continue
77end
78if eq get inbuf ls 10
79continue
80end
81if eq get inbuf ls 35
82continue
83end
84if not rw_parse_tsv_sample part inbuf ls ll sample
85w = rw_write_all 2 rw_cli_err_parse len rw_cli_err_parse
86if not w
87ret 2
88end
89ret 1
90end
91rc = rw_ingest ring rbuf sample
92if ne rc 0
93w = rw_write_all 2 rw_cli_err_ingest len rw_cli_err_ingest
94if not w
95ret 2
96end
97ret 1
98end
99end
100stats = new RwStats 0 0 0 0 0 0 0
101if not rw_compute_stats ring rbuf RW_METRIC_GPU_TEMP 0 stats
102w = rw_write_all 2 rw_cli_err_empty len rw_cli_err_empty
103if not w
104ret 2
105end
106ret 1
107end
108th = new RwThresh 85 250 90 98 115000
109alarms = rw_check_alarms ring rbuf th
110outbuf = new uchar 512 0
111olen = long 0
112if rw_want_text
113olen = rw_format_stats_text outbuf stats alarms
114else
115olen = rw_format_stats_json outbuf stats alarms
116end
117if lt olen 0
118ret 1
119end
120ok = rw_write_all 1 outbuf ulong olen
121if not ok
122ret 1
123end
124ret 0
125end