From 6cb07327b717603be983fdd6df0e6d9009aae39a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 16:00:52 -0300 Subject: replica: what stopped each input's speculation is counted by name (PARDES_REPLICA_STATS's `stops`: a host function's, a site's, or a poison's reason, which tape.poison now takes; PARDES_REPLICA_TRACE says it with the input); a window client's PARDES_TEST_LATENCY says each input (`I seq ns at-once`) and, after each unit, the first of its own not confirmed (`U ns seq`), so a harness finds the frame that shows an input that waited Co-Authored-By: Claude Opus 5.5 --- src/replica.zig | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/replica.zig') diff --git a/src/replica.zig b/src/replica.zig index 1cf68db2..a88873ac 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -480,6 +480,30 @@ pub const Stats = struct { copies: u32 = 0, /// Nanoseconds: a terminal's delta applied. apply_ns: std.ArrayListUnmanaged(u64) = .empty, + /// What stopped them (`Tape.poisoned_by`), a count a name. + stops: [16]Stop = @splat(.{}), + + const Stop = struct { name: []const u8 = "", n: u32 = 0 }; + + fn stop(s: *Stats, name: []const u8) void { + for (&s.stops) |*st| if (st.n == 0 or std.mem.eql(u8, st.name, name)) { + st.name = name; + st.n += 1; + return; + }; + } + + /// `name:n,...` (spaces as dashes), or `-`. + fn writeStops(s: *const Stats, w: *std.Io.Writer) !void { + var any = false; + for (s.stops) |st| if (st.n > 0) { + if (any) try w.writeByte(','); + any = true; + for (st.name) |ch| try w.writeByte(if (ch == ' ') '-' else ch); + try w.print(":{d}", .{st.n}); + }; + if (!any) try w.writeByte('-'); + } pub fn deinit(s: *Stats, gpa: Allocator) void { s.spec_ns.deinit(gpa); @@ -854,7 +878,7 @@ pub const Replica = struct { // emulator (rows, cursor, modes), which here is the last delta's and // there what the pty has said since. It waits; phase 6 predicts the // echo. - if (r.t.screen_state) if (c.panes[c.active]) |pane| if (pane.isTerminal()) tape.poison(); + if (r.t.screen_state) if (c.panes[c.active]) |pane| if (pane.isTerminal()) tape.poison("a terminal has the keyboard"); c.update(in.event); c.step(); const clean = tape.endSpeculation(&r.t); @@ -865,7 +889,8 @@ pub const Replica = struct { // Undone, and the earlier ones applied again on the confirmed // position: this one waits for the authority. r.stats.stopped += 1; - if (std.c.getenv("PARDES_REPLICA_TRACE") != null) std.debug.print("replica {d}: its input {d} ({t}) stopped at a host call: it waits\n", .{ r.id, p.seq, in.event }); + r.stats.stop(r.t.poisoned_by); + if (std.c.getenv("PARDES_REPLICA_TRACE") != null) std.debug.print("replica {d}: its input {d} ({t}) stopped at a host call ({s}): it waits\n", .{ r.id, p.seq, in.event, r.t.poisoned_by }); r.blocked = p.seq; const upto = r.applied; r.toConfirmed(); @@ -2796,17 +2821,22 @@ pub const Link = struct { /// went, a line at its end (test/daemon.py, the gates). pub fn writeStats(c: *Link, path: []const u8) void { const st = &c.r.stats; - var buf: [600]u8 = undefined; + var buf: [1024]u8 = undefined; const e = &c.r.echo.stats; - const line = std.fmt.bufPrint(&buf, "inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d}\n", .{ + var w: std.Io.Writer = .fixed(&buf); + w.print("inputs {d} at_once {d} stopped {d} units {d} fast {d} neutral {d} mispredicted {d} foreign {d} visible {d} rtt_us {d} spec_us {d}/{d} copy_us {d}/{d} rollback_us {d}/{d} join_ms {d} blobs {d} from_memory {d} from_disk {d} sent_kb {d} echo {d}/{d} confirmed {d} missed {d}", .{ st.inputs, st.speculated, st.stopped, st.units, st.fast, c.r.neutral, st.mispredicted, st.foreign, c.visible, c.r.rtt_ns / 1000, pctOf(st.spec_ns.items, 50) / 1000, pctOf(st.spec_ns.items, 99) / 1000, pctOf(st.copy_ns.items, 50) / 1000, pctOf(st.copy_ns.items, 99) / 1000, pctOf(st.rollback_ns.items, 50) / 1000, pctOf(st.rollback_ns.items, 99) / 1000, c.join_ms, c.join.blobs, c.join.from_memory, c.join.from_disk, c.join.sent_bytes >> 10, e.predicted, e.predicted + e.unpredicted, e.confirmed, e.mispredicted, }) catch return; + // What stopped its inputs, last: a word a pair before it. + w.writeAll(" stops ") catch return; + st.writeStops(&w) catch return; + w.writeByte('\n') catch return; var z: [4096]u8 = undefined; - appendTo(std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return, line); + appendTo(std.fmt.bufPrintSentinel(&z, "{s}", .{path}, 0) catch return, w.buffered()); } /// The link ended: whether the client joins again, and why in its -- cgit v1.3