diff options
Diffstat (limited to 'core/Term.zig')
| -rw-r--r-- | core/Term.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/Term.zig b/core/Term.zig index 82d5dad7..9f5d6362 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -14,6 +14,15 @@ const dump = @import("dump.zig"); const File = @import("File.zig"); const iface = plain.term; +/// Writes into this process's emulators (a read fed, a grid reflowed, a +/// view moved, one opened, closed, loaded or made again): whether a unit's +/// replay made one, the replica engine's one rule (core/replica.zig +/// `confirm`) reads across that replay, on its one thread. +pub var writes: u32 = 0; +/// The reloads this process made (a join's, on every side) and their time, +/// for the soak's join line (test/replicas.zig `--bytes`). +pub var reloads: struct { n: u32 = 0, ns: u64 = 0, worst_ns: u64 = 0 } = .{}; + /// The terminal module's entries; null in a core built without it. pub const ops: ?*const iface.Ops = if (@import("term_options").terminal) &@import("term").ops else null; @@ -94,6 +103,9 @@ pub const State = struct { defer arena.deinit(); const parts = try walk.load(iface.Parts, arena.allocator(), bytes[8..][0..n], null); out.* = .{ .impl = try o.load(gpa, bytes[8 + n ..], &parts) }; + writes +%= 1; + // A replica's (a join's, a closed terminal brought back in a step). + if (tape.replaying() or dump.terminal_gpa != null) o.direct(out.impl); } }; @@ -114,6 +126,10 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State { const s = try gpa.create(State); errdefer gpa.destroy(s); s.* = .{ .impl = try o.open(gpa, cols, rows) }; + writes +%= 1; + // A replica's emulator loads its program's images by direct data alone + // (P32): what is read off the session's machine is the session's. + if (tape.replaying()) o.direct(s.impl); return s; } @@ -121,6 +137,7 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State { /// one it was opened with): the allocator a caller hands is not used. pub fn close(s: *State, _: std.mem.Allocator) void { const own = the().gpa(s.impl); + writes +%= 1; the().close(s.impl); own.destroy(s); } @@ -130,6 +147,14 @@ pub fn close(s: *State, _: std.mem.Allocator) void { /// history a page at a time, and a snapshot does not say how its rows were /// cut into pages). The snapshot's hash, which every side compares. pub fn reload(s: *State) !u64 { + writes +%= 1; + const t0 = @import("FrameStats.zig").nowNs(); + defer { + reloads.n += 1; + const dt = @import("FrameStats.zig").nowNs() -| t0; + reloads.ns += dt; + reloads.worst_ns = @max(reloads.worst_ns, dt); + } return the().reload(s.impl); } @@ -142,6 +167,7 @@ pub fn due(s: *const State) ?u64 { /// Loaded from a dump without its shell: its program's modes reset, its /// history marked off from what the next shell prints. pub fn revive(s: *State) void { + writes +%= 1; the().revive(s.impl); } @@ -160,6 +186,7 @@ pub fn stop() void { /// One read of its program's output (`Told` says where the tracked rows /// went). pub fn feed(s: *State, bytes: []const u8, tracked: []const i32, rows: []i32, erased: []bool) Told { + writes +%= 1; return the().feed(s.impl, bytes, tracked, rows, erased); } @@ -171,25 +198,30 @@ pub fn grid(s: ?*const State) Grid { /// Its view to a row of its history, or onto its output (null). pub fn viewTo(s: *State, at: ?usize) void { + writes +%= 1; the().viewTo(s.impl, at); } /// Its view moved by a number of rows (negative scrolls back). pub fn scroll(s: *State, delta: i32) void { + writes +%= 1; the().scroll(s.impl, delta); } /// Its view back onto its output. pub fn follow(s: *State) void { + writes +%= 1; the().follow(s.impl); } /// Its grid reflowed, now or when `resizeDeferred` makes it. pub fn resize(s: *State, cols: u16, rows: u16, later: bool) void { + writes +%= 1; the().resize(s.impl, cols, rows, later); } pub fn resizeDeferred(s: *State) bool { + writes +%= 1; return the().resizeDeferred(s.impl); } |
