From 233d9cf30b178501e3194297434791b6de35eff2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:21:44 -0300 Subject: ring: a record larger than the ring is dropped and counted, not asserted on --- src/trace/Ring.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/trace/Ring.zig') 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" { -- cgit v1.3