ludic/packages/ludic.telemetry/queries.ludic
Orkuncakilkaya d1bea7f10e 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>
2026-09-28 15:15:12 +03:00

34 lines
1.9 KiB
Text

# queries.ludic - what the game (a Settings row, a test) asks, and a reset back to before start
export function telemetry_id(telemetry_st: TelemetryState) -> string { return telemetry_st.telemetry__id }
export function telemetry_session(telemetry_st: TelemetryState) -> string { return telemetry_st.telemetry__session }
export function telemetry_ready(telemetry_st: TelemetryState) -> bool { return telemetry_st.telemetry__ready }
export function telemetry_get_config(telemetry_st: TelemetryState) -> TelemetryConfig { return telemetry__conf(telemetry_st) }
export function telemetry_fails(telemetry_st: TelemetryState) -> int { return telemetry_st.telemetry__fails }
export function telemetry_next_ms(telemetry_st: TelemetryState) -> int { return telemetry_st.telemetry__next_ms }
export function telemetry_in_flight(telemetry_st: TelemetryState) -> bool { return telemetry_st.telemetry__h >= 0 }
export function telemetry_queued(telemetry_st: TelemetryState) -> int { return telemetry_st.telemetry__n }
# a queued line as it will be sent, player mark and all
export function telemetry_line(telemetry_st: TelemetryState, i: int) -> string {
let sb = sb_new(TELEMETRY_LINE)
tr_line_to(telemetry_st, i, sb, null)
return text_of(sb.b, sb_len(sb))
}
# back to before telemetry_start, ports and config kept (tests; a start after a failed boot)
export function telemetry_reset(telemetry_st: mut TelemetryState) -> void {
telemetry__drop_request(telemetry_st)
telemetry_st.telemetry__ready = false
telemetry_st.telemetry__id = ""
telemetry_st.telemetry__session = ""
if telemetry_st.telemetry__ring != null { tr_clear(telemetry_st) }
telemetry_st.telemetry__dirty = false
telemetry_st.telemetry__sent_n = 0
telemetry_st.telemetry__next_ms = 0
telemetry_st.telemetry__saved_ms = 0
telemetry_st.telemetry__fails = 0
telemetry_st.telemetry__clock_on = false
telemetry_st.telemetry__proc = -1
q_clear(telemetry_facts(telemetry_st))
}