Skip to content

sim: port the scenario stats collector (ScenarioStats)#69

Merged
ch4r10t33r merged 1 commit into
mainfrom
feat/collector-scenariostats-60
Jul 3, 2026
Merged

sim: port the scenario stats collector (ScenarioStats)#69
ch4r10t33r merged 1 commit into
mainfrom
feat/collector-scenariostats-60

Conversation

@ch4r10t33r

Copy link
Copy Markdown
Collaborator

Closes #60.

Ports sim/collector.go's data types and aggregation to src/sim/collector.zig — there was no Zig counterpart.

What it does

  • Types: NodeEvent, BandwidthEvent, ChunkStats, ScenarioStats (all fields mirrored: published/received maps, per-node latency, origin/relay + transport byte totals, chunk-verdict tallies).
  • StatsCollector: correlates publish/receive events into per-node, per-message delivery and latency (received_at − published_at), plus recordBandwidth (transport totals), addOriginBytes/addRelayBytes, and recordChunkVerdict.

Adaptations (documented in the module header)

  • Go drains channels from a goroutine (Run); the Zig sim is synchronous, so StatsCollector exposes record* methods called directly. The channel/context.Context loop and the slog LogCollector are the goroutine/logging carve-out per UPSTREAM.md.
  • time.Time → an at_us microsecond timestamp supplied by the caller (matching how the Zig sim threads time elsewhere).
  • ScenarioStats owns all keys and payload copies; deinit frees the nested maps.

Tests

Four tests, run under the leak-checking std.testing.allocator:

  • publish→receive delivery + latency correlation (multiple receivers),
  • receive-before-publish (no latency entry),
  • duplicate-receive overwrite (no leak),
  • bandwidth / origin-relay bytes / chunk-verdict aggregation (incl. invalid/pending not tallied by ChunkStats).

Verified on stock Zig 0.16.0: zig fmt --check and zig build test pass. README implementation-status table lists sim.collector.

Ports `sim/collector.go`'s data types and aggregation to
`src/sim/collector.zig`: `NodeEvent`, `BandwidthEvent`, `ChunkStats`,
`ScenarioStats`, and a `StatsCollector` that correlates publish/receive
events into per-node, per-message delivery + latency, plus transport-byte
totals, origin/relay byte tallies, and chunk-verdict counts.

The Go collector drains channels from a goroutine; the Zig sim is
synchronous, so `StatsCollector` exposes `record*` methods called directly
(the context/channel `Run` loop and the slog `LogCollector` are the
goroutine/logging carve-out per UPSTREAM.md). `time.Time` becomes an
`at_us` microsecond timestamp supplied by the caller. `ScenarioStats`
owns all keys/payload copies; `deinit` frees the nested maps.

Four tests cover delivery+latency correlation, receive-before-publish,
duplicate-receive overwrite (leak-checked), and byte/verdict aggregation.
README implementation-status table lists `sim.collector`.

Closes #60.
@ch4r10t33r ch4r10t33r merged commit a906330 into main Jul 3, 2026
7 checks passed
@ch4r10t33r ch4r10t33r deleted the feat/collector-scenariostats-60 branch July 3, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sim: port the scenario collector / ScenarioStats metrics

1 participant