sim: port the scenario stats collector (ScenarioStats)#69
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #60.
Ports
sim/collector.go's data types and aggregation tosrc/sim/collector.zig— there was no Zig counterpart.What it does
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), plusrecordBandwidth(transport totals),addOriginBytes/addRelayBytes, andrecordChunkVerdict.Adaptations (documented in the module header)
Run); the Zig sim is synchronous, soStatsCollectorexposesrecord*methods called directly. The channel/context.Contextloop and the slogLogCollectorare the goroutine/logging carve-out perUPSTREAM.md.time.Time→ anat_usmicrosecond timestamp supplied by the caller (matching how the Zig sim threads time elsewhere).ScenarioStatsowns all keys and payload copies;deinitfrees the nested maps.Tests
Four tests, run under the leak-checking
std.testing.allocator:invalid/pendingnot tallied byChunkStats).Verified on stock Zig 0.16.0:
zig fmt --checkandzig build testpass. README implementation-status table listssim.collector.