diff options
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/replica.zig b/src/replica.zig index a6014f5b..ba5ca55f 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -494,6 +494,10 @@ pub const Stats = struct { foreign: u32 = 0, rebases: u32 = 0, units: u32 = 0, + /// The samples below kept: an in-process harness's replica, or a + /// client's with PARDES_REPLICA_STATS. Without, nothing is: a client + /// runs for days, and they grew a word an input and a delta. + samples: bool = false, /// Nanoseconds: one speculative apply, a copy taken, a rollback (the /// copy put back, the confirmed units replayed, the pending reapplied). spec_ns: std.ArrayListUnmanaged(u64) = .empty, @@ -612,10 +616,11 @@ pub const Replica = struct { }; /// A replica of the session whose first unit is `first`; `screens` - /// as the authority's (its terminals fed by `screen`). + /// as the authority's (its terminals fed by `screen`). In process, its + /// timing samples kept for the harness that reads them. pub fn init(gpa: Allocator, id: u16, first: []const u8, screens: bool) !*Replica { const r = try gpa.create(Replica); - r.* = .{ .gpa = gpa, .id = id, .t = tape.memory(gpa) }; + r.* = .{ .gpa = gpa, .id = id, .t = tape.memory(gpa), .stats = .{ .samples = true } }; r.t.screen_state = screens; r.t.core_gpa = r.epoch.allocator(); r.confirm(first); @@ -906,7 +911,7 @@ pub const Replica = struct { defer was.end(); while (r.applied < r.pending.items.len and r.blocked != r.pending.items[r.applied].seq) if (!r.speculate()) break; if (r.recovering) |t0| { - r.stats.rollback_ns.append(r.gpa, nowNs() - t0) catch {}; + if (r.stats.samples) r.stats.rollback_ns.append(r.gpa, nowNs() - t0) catch {}; r.recovering = null; } } @@ -926,7 +931,7 @@ pub const Replica = struct { r.copy.take(&r.epoch, c) catch return false; r.keepViews(); rollback.Epoch.select(&r.epoch); - r.stats.copy_ns.append(r.gpa, nowNs() - t0) catch {}; + if (r.stats.samples) r.stats.copy_ns.append(r.gpa, nowNs() - t0) catch {}; r.stats.copy_bytes += r.copy.savedBytes(); r.stats.copies += 1; } @@ -981,7 +986,7 @@ pub const Replica = struct { } } r.stats.speculated += 1; - r.stats.spec_ns.append(r.gpa, dt) catch {}; + if (r.stats.samples) r.stats.spec_ns.append(r.gpa, dt) catch {}; p.spec = r.gpa.dupe(u8, tape.taken(&r.t)) catch return false; tape.clearTaken(&r.t); r.applied += 1; @@ -1016,7 +1021,7 @@ pub const Replica = struct { defer rollback.Epoch.select(null); r.copy.take(&r.epoch, c) catch return; r.keepViews(); - r.stats.copy_ns.append(r.gpa, nowNs() - t0) catch {}; + if (r.stats.samples) r.stats.copy_ns.append(r.gpa, nowNs() - t0) catch {}; r.stats.copy_bytes += r.copy.savedBytes(); r.stats.copies += 1; } @@ -1085,7 +1090,7 @@ pub const Replica = struct { sc.refused = true; return r.screenMessage(m.pane, m.serial, kind_reset, &.{}); }; - r.stats.apply_ns.append(r.gpa, nowNs() - t0) catch {}; + if (r.stats.samples) r.stats.apply_ns.append(r.gpa, nowNs() - t0) catch {}; sc.refused = false; terminal.takeMarks(state, applied.extra); r.echo.delta(c, m.pane, sc.rep.top); @@ -1743,7 +1748,9 @@ pub const Peers = struct { state_bytes: usize = 0, /// What each client input cost the session (its step, its unit sent), /// and each boundary (its pump's unit sent, what came taken in), ns: - /// PARDES_REPLICA_STATS writes them at the session's end. + /// PARDES_REPLICA_STATS writes them at the session's end, and only then + /// are these and `each_join` kept (`samples`): a session runs for days. + samples: bool = false, input_ns: std.ArrayListUnmanaged(u64) = .empty, boundary_ns: std.ArrayListUnmanaged(u64) = .empty, cut: u32 = 0, @@ -1819,7 +1826,7 @@ pub const Peers = struct { pub fn boundary(ps: *Peers, core: *Pardes) void { if (!ps.recording and !ps.mail.load(.acquire)) return; const t0 = nowNs(); - defer if (ps.recording) ps.boundary_ns.append(ps.gpa, nowNs() - t0) catch {}; + defer if (ps.recording and ps.samples) ps.boundary_ns.append(ps.gpa, nowNs() - t0) catch {}; if (ps.recording) { // The rows the pump's steps read, then its unit, then what the // terminals came to (the next steps read that). @@ -1869,7 +1876,7 @@ pub const Peers = struct { fn input(ps: *Peers, core: *Pardes, peer: *Peer, msg: []const u8) void { const in = parseInput(msg) orelse return; const t0 = nowNs(); - defer ps.input_ns.append(ps.gpa, nowNs() - t0) catch {}; + defer if (ps.samples) ps.input_ns.append(ps.gpa, nowNs() - t0) catch {}; // The terminals as this step reads them, then the step, the rows // it read, its unit (part B terminal notes' order). ps.screensOut(core, .flush); @@ -1954,7 +1961,7 @@ pub const Peers = struct { const t0 = nowNs(); defer { ps.join_ns = @max(ps.join_ns, nowNs() - t0); - ps.each_join.append(ps.gpa, nowNs() - t0) catch {}; + if (ps.samples) ps.each_join.append(ps.gpa, nowNs() - t0) catch {}; } const slot = for (&ps.list) |*s| { if (s.* == null) break s; @@ -1972,6 +1979,7 @@ pub const Peers = struct { ps.screens = .init(ps.gpa); tape.on = &ps.t; ps.recording = true; + ps.samples = std.c.getenv("PARDES_REPLICA_STATS") != null; } // Someone looks at it now: its messages go by keys, not the clock. core.unattended = false; @@ -2820,6 +2828,8 @@ pub const Link = struct { }; // PARDES_NO_ECHO: no predicted echo (the gates' baseline). if (std.c.getenv("PARDES_NO_ECHO") != null) r.echo.on = false; + // PARDES_REPLICA_STATS: its timing samples kept, for its line. + r.stats.samples = std.c.getenv("PARDES_REPLICA_STATS") != null; if (!r.loaded(joined.digest)) { r.deinit(); _ = std.fmt.bufPrint(why, "the session's dump loaded as another session (a build's dump is not complete)\x00", .{}) catch {}; |
