fix(ludic.telemetry): nothing made per event - properties and the line written into kept buffers, the queue a ring of bytes made at the start
An event was a tree of values encoded into a new string, a dropped line was never given back, and every batch and save joined the queue into another. Now: telemetry_props / telemetry_str / _int / _bool write the properties as JSON into a buffer the state keeps; the line is written beside it, its time worked out from the clock's seconds (TelemetryWorld.clock_s, was stamp); its bytes go into one ring (ring_bytes, at most queue_max lines), the oldest overwritten past either; a batch and the file are written into a third kept buffer and go as bytes (TelemetryTransport.send takes the bytes and their length; Http.body_bytes, Fs.write_bytes). The facts are pooled. tests/ring_test: ten thousand events past the cap in lines and in bytes, 0 bytes of heap; the line exact JSON, escaped, 2000-02-29 right; the batch puts the id in; the file round-trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fc0f3d3790
commit
d1bea7f10e
14 changed files with 454 additions and 97 deletions
46
packages/ludic.telemetry/load.ludic
Normal file
46
packages/ludic.telemetry/load.ludic
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# load.ludic - the unsent lines a start finds on disk, read once into the ring with their marks found
|
||||
function telemetry__queue_load(telemetry_st: mut TelemetryState) -> void {
|
||||
let f = telemetry__conf(telemetry_st).queue_file
|
||||
if len(f) == 0 { return }
|
||||
let b = Fs.read_bytes(f)
|
||||
if b == null { return }
|
||||
var start = 0
|
||||
for i in 0 .. len(b) + 1 {
|
||||
if i == len(b) or b[i] == 10 {
|
||||
if i - start > 2 { tq_load_line(telemetry_st, b, start, i - start) }
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
telemetry_st.telemetry__dirty = false
|
||||
}
|
||||
# a line read back (once, at a start): through the kept line buffer, its mark found again
|
||||
function tq_load_line(telemetry_st: mut TelemetryState, b: []byte, at: int, n: int) -> void {
|
||||
let sb = telemetry_st.telemetry__line
|
||||
sb_clear(sb)
|
||||
for i in 0 .. n { sb_byte(sb, b[at + i]) }
|
||||
if tj_full(sb) { return }
|
||||
tr_add(telemetry_st, sb.b, n, tq_find_mark(sb.b, n))
|
||||
}
|
||||
function tq_find_mark(b: []byte, n: int) -> int {
|
||||
let m: string = TELEMETRY_MARK
|
||||
let k = len(m)
|
||||
for i in 0 .. n - k + 1 {
|
||||
var same = true
|
||||
for j in 0 .. k { if same and b[i + j] != m[j] { same = false } }
|
||||
if same { return i }
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function telemetry__read_obj(path: string) -> Val {
|
||||
if len(path) == 0 { return null }
|
||||
let s = Fs.read_text(path)
|
||||
if s == null { return null }
|
||||
let v = Json.parse(s)
|
||||
if v == null { return null }
|
||||
if Value.kind(v) != 6 {
|
||||
Json.free(v)
|
||||
return null
|
||||
}
|
||||
return v
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue