summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig40
1 files changed, 35 insertions, 5 deletions
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