summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:21:44 -0300
committerGabriel Schneider <[email protected]>2026-11-10 11:21:44 -0300
commit233d9cf30b178501e3194297434791b6de35eff2 (patch)
tree2a0e6f593e018007f9f28d1555b5f11cc4504047 /src
parent7f1adc581deba868f5ad04b55e34027ae70f899e (diff)
downloadcomputeranim-233d9cf30b178501e3194297434791b6de35eff2.tar.gz
computeranim-233d9cf30b178501e3194297434791b6de35eff2.zip
ring: a record larger than the ring is dropped and counted, not asserted on
Diffstat (limited to 'src')
-rw-r--r--src/trace/Ring.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/trace/Ring.zig b/src/trace/Ring.zig
index 47b490b..b92ae61 100644
--- a/src/trace/Ring.zig
+++ b/src/trace/Ring.zig
@@ -112,7 +112,12 @@ fn futexWake(word: *const std.atomic.Value(u32)) void {
pub fn emit(r: *Ring, ev: Event, payload: []const u8) void {
const h = r.hdr;
const need = record_overhead + std.mem.alignForward(usize, payload.len, 8);
- std.debug.assert(need <= h.capacity);
+ // A record the ring could never hold is dropped, not waited for: the
+ // caller splits large payloads (a `mem_write` by address).
+ if (need > h.capacity) {
+ _ = h.dropped.fetchAdd(1, .monotonic);
+ return;
+ }
var at = h.head.load(.monotonic);
while (true) {
if (at + need - h.tail.load(.acquire) > h.capacity) {
@@ -240,6 +245,12 @@ test "a second mapping sees the first's events; a full lossy ring drops" {
for (0..100) |i| a.emit(.{ .kind = .step, .a = .{ i, 0, 0, 0, 0, 0 } }, "");
try std.testing.expectEqual(4096 / record_overhead, 100 - a.hdr.dropped.load(.monotonic));
try std.testing.expectEqual(@as(u64, 0), b.peek().?.ev.a[0]);
+ // One too large for the ring at all is dropped too, lossy or not.
+ a.hdr.lossy.store(0, .monotonic);
+ const dropped = a.hdr.dropped.load(.monotonic);
+ var big: [4096]u8 = undefined;
+ a.emit(.{ .kind = .mem_write }, &big);
+ try std.testing.expectEqual(dropped + 1, a.hdr.dropped.load(.monotonic));
}
test "producers on other threads, a stop and a resume" {