diff options
Diffstat (limited to 'anim/src/syscalls.zig')
| -rw-r--r-- | anim/src/syscalls.zig | 98 |
1 files changed, 74 insertions, 24 deletions
diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index a19324f..67085c2 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -11,9 +11,11 @@ const sk = @import("sketch"); const anim = @import("anim"); const zt = @import("ztrace"); const ui = @import("ui.zig"); +const rows = @import("rows.zig"); const cursors = @import("cursor.zig"); const Recording = @import("Recording.zig"); const context = @import("context.zig"); +const hexdump = @import("hexdump.zig"); const Stage = @import("stage.zig").Stage; const theme = ui.theme; const time = theme.time; @@ -27,8 +29,8 @@ const k = theme.color.on_kernel; /// kernel's side change, the last call giving way to this one, its name, /// its rows, its card; the work is done a byte at a time (a call with /// none skips it); the arrow comes back, and what came back strikes rax. -/// So a call is as long as what it does: `close` 3.7 s, a `read` of -/// fifteen bytes 4.8. +/// So a call is as long as what it does: `close` 4.0 s, a `read` of +/// fifteen bytes 5.1. pub const Plan = struct { registers: f32 = time.cascade, enters: f32 = 0.80, @@ -43,11 +45,14 @@ pub const Plan = struct { work: f32 = 2.00, fills: f32 = 2.40, bytes: f32 = 0, - /// The arrow back sets off; rax is struck; the mark moves on. + /// The arrow back sets off; rax is struck; the `returns` row takes the + /// value; the program stores what came back (memory, after its + /// cause); the mark moves on. back: f32 = 2.00, returns: f32 = 2.40, - advance: f32 = 3.10, - total: f32 = 3.70, + stored: f32 = 2.80, + advance: f32 = 3.40, + total: f32 = 4.00, pub const cross = 0.40; pub const row = 0.10; @@ -61,7 +66,8 @@ pub const Plan = struct { p.bytes = @floatFromInt(@max(down, @min(up, 32))); if (p.bytes > 0) p.back = p.fills + p.bytes * byte + 10.0 / 60.0; p.returns = p.back + cross; - p.advance = p.returns + row + time.read_value; + p.stored = p.returns + row + time.cascade; + p.advance = p.stored + time.read_value; p.total = p.advance + time.step + time.rest; return p; } @@ -69,12 +75,14 @@ pub const Plan = struct { /// The same as the cursor's plan: the registers are the CPU's level, /// the bytes memory's. pub fn step(p: Plan) cursors.Plan { - return .{ .at = .{ p.registers, p.fills, p.fills }, .advance = p.advance, .travel = time.step, .total = p.total }; + return .{ .at = .{ p.registers, p.stored, p.stored }, .advance = p.advance, .travel = time.step, .total = p.total }; } }; /// How many of the bytes a call was given the kernel's side shows. -const shown_bytes = 2 * 11; +/// Ten a row, two rows, in the drawing's 880 beside the arrows. +const per_row = 10; +const shown_bytes = 2 * per_row; /// One line of the program and the call into the kernel it makes, as one /// step of the cursor, timed by the crossing. A line that makes no call @@ -144,9 +152,13 @@ pub const Crossing = struct { const size = theme.size.mono.context; pub fn draw(c: *const Crossing, f: *sk.Frame, placed: anim.Placed) void { + c.view(f, placed); const box = c.stage.box(placed, .band); if (box.h < theme.metric.context.tag + 24) return; - const u = context.at(f, placed, box); + const u = context.at(f, placed, box).faded(placed.value(c.stage.drawing)); + // A relayout moves the band: what is drawn in it stays inside it. + u.clip(.{ .x = 0, .y = 0, .w = box.w, .h = box.h }); + defer u.unclip(); const now = c.cursor.now(placed); const rec = c.cursor.rec; const body = u.panel(box.w, box.h, "kernel", .{ .focus = c.focus, .note = "the other side of a system call" }); @@ -183,19 +195,44 @@ pub const Crossing = struct { if (gold) v.fill(card, theme.mark(.current).solid); v.frame(card, k.ink, theme.stroke.rule); const name = zt.syscalls.name(done.nr) orelse "?"; - v.text(if (gold) .mono_bold else .mono, size, card.x + 8, theme.baseline(card.y, card.h, size), name[0..@min(name.len, 11)], k.ink); - if ((i != newest or t >= p.returns + Plan.row) and done.exit != null) { - const words = result(u, done); - if (words.len <= 4) v.text(.mono, size, card.x + card.w - 8 - u.width(.mono, size, words), theme.baseline(card.y, card.h, size), words, k.dim); - } + // The result ranged right, when it is short; the name has the rest, and is cut only there. + const words = if ((i != newest or t >= p.returns + Plan.row) and done.exit != null) result(u, done) else ""; + const said = if (words.len > 0 and words.len <= 4) words else ""; + if (said.len > 0) v.text(.mono, size, card.x + card.w - 8 - u.width(.mono, size, said), theme.baseline(card.y, card.h, size), said, k.dim); + v.text(if (gold) .mono_bold else .mono, size, card.x + 8, theme.baseline(card.y, card.h, size), rows.fitted(u, name, card.w - 16 - (if (said.len > 0) u.width(.mono, size, said) + 12 else 0)), k.ink); } } + /// Its view: the bytes the newest call is given or fills (its path, a + /// buffer), as a dump over the state column; struck as the kernel + /// fills them. + fn view(c: *const Crossing, f: *sk.Frame, placed: anim.Placed) void { + const rec = c.cursor.rec; + const now = c.cursor.now(placed); + var newest = latest(rec, now.stops[0]); + // No effect before its cause: until the kernel has taken the call, the last one's bytes. + if (newest) |n| if (rec.syscalls[n].enter > now.stops[1] and now.walking() and now.time < Plan.of(rec.syscalls[n]).name) { + newest = if (n > 0) n - 1 else null; + }; + const made: ?Recording.Syscall = if (newest) |n| rec.syscalls[n] else null; + const span: ?Recording.Span = if (made) |given| bufferRead(given) orelse fills(given) orelse if (given.text.len > 0 and std.mem.indexOfScalar(u8, zt.syscalls.signature(given.nr), 's') != null) .{ .addr = given.args[0], .len = given.text.len + 1 } else null else null; + const scratch = context.at(f, placed, c.stage.box(placed, .view)); + const about = if (span) |sp| scratch.print("the {s}, {x} to {x}", .{ if (bufferRead(made.?) != null) "buffer given" else if (fills(made.?) != null) "buffer filled" else "path given", sp.addr, sp.addr + sp.len - 1 }) else "the call names no bytes"; + const v = hexdump.panel(f, placed, c.stage, about, &.{}); + defer v.u.unclip(); + const sp = span orelse return; + if (v.rows == 0) return; + const first = sp.addr & ~@as(u64, 15); + const n = @min(v.rows, (sp.addr + sp.len - first + 15) / 16); + hexdump.draw(v.u, now, 0, theme.metric.context.tag + theme.metric.context.pad, first, n, .{ .region = context.ink(context.regionOf(now.moment(), sp.addr)) }); + v.veil(now); + } + /// A call, decoded: its name, a row for each argument, what came /// back; and to the right the bytes it was given, as the kernel /// copies them. fn call(c: *const Crossing, u: ui.Ui, body: Rect, made: Recording.Syscall, p: Plan, t: f32) void { - _ = c; + const rec = c.cursor.rec; const x = 236; const name = zt.syscalls.name(made.nr) orelse "syscall"; // The name arrives rising, as a caption does. @@ -208,22 +245,28 @@ pub const Crossing = struct { var row_y: f32 = body.y + 62; var text_used = false; const row = struct { - fn draw(v: ui.Ui, y: f32, register: []const u8, meaning: []const u8, words: []const u8) void { + /// `note`: faint after the words, what a descriptor is open on (the `value` class `fd`). + fn draw(v: ui.Ui, y: f32, register: []const u8, meaning: []const u8, words: []const u8, note: []const u8) void { v.fill(.{ .x = x, .y = y, .w = 300, .h = theme.stroke.rule }, k.rule); const base = theme.baseline(y, row_h + 4, size); v.text(.mono, size, x, base, register, k.dim); v.text(.sans_medium, theme.size.sans.tag, x + 52, base, meaning, k.ink); v.text(.mono, size, x + 130, base, words, k.ink); + v.text(.mono, size, x + 130 + v.width(.mono, size, words) + 8, base, note, k.dim); } }.draw; for (signature, 0..) |kind, arg| { if (arg >= 4) break; const shows = std.math.clamp((t - p.rows - @as(f32, @floatFromInt(arg)) * Plan.row) / Plan.row, 0, 1); - row(u.faded(shows), row_y, carriers[arg], what(made.nr, kind, arg), value(u, made, kind, arg, &text_used)); + const meaning = what(made.nr, kind, arg); + const note = if (std.mem.eql(u8, meaning, "fd")) rec.openOn(u.f.scratch, made.args[arg], made.enter) else ""; + row(u.faded(shows), row_y, carriers[arg], meaning, value(u, made, kind, arg, &text_used), note); row_y += row_h + 4; } const back = t >= p.returns + Plan.row and made.exit != null; - row(u.faded(std.math.clamp((t - p.rows - @as(f32, @floatFromInt(@min(signature.len, 4))) * Plan.row) / Plan.row, 0, 1)), row_y, "rax", "returns", if (back) result(u, made) else "\u{2014}"); + // What `open` returns is a descriptor: open on the path it was given. + const opened = back and std.mem.eql(u8, zt.syscalls.name(made.nr) orelse "", "open") and @as(i64, @bitCast(made.result)) >= 0; + row(u.faded(std.math.clamp((t - p.rows - @as(f32, @floatFromInt(@min(signature.len, 4))) * Plan.row) / Plan.row, 0, 1)), row_y, "rax", "returns", if (back) result(u, made) else "\u{2014}", if (opened) rec.openOn(u.f.scratch, made.result, made.exit.? + 1) else ""); if (made.text.len == 0) return; const bytes_x = 564; @@ -231,7 +274,7 @@ pub const Crossing = struct { framed.text(.sans, theme.size.sans.micro, bytes_x, body.y + 22, if (std.mem.indexOfScalar(u8, signature, 's') != null) "the path it was given" else "the bytes it was given", k.dim); const shown = @min(made.text.len, shown_bytes); for (made.text[0..shown], 0..) |byte, j| { - const cell: Rect = .{ .x = bytes_x + @as(f32, @floatFromInt(j % 11)) * 28, .y = body.y + 32 + @as(f32, @floatFromInt(j / 11)) * 30, .w = 26, .h = 26 }; + const cell: Rect = .{ .x = bytes_x + @as(f32, @floatFromInt(j % per_row)) * 28, .y = body.y + 32 + @as(f32, @floatFromInt(j / per_row)) * 30, .w = 26, .h = 26 }; // Each fills as it is copied, two frames a byte: struck, then held. const since = t - p.fills - @as(f32, @floatFromInt(j)) * Plan.byte; if (since < 0) { @@ -253,7 +296,8 @@ pub const Crossing = struct { /// ones that carried it), into the kernel, as the call enters; and back /// down as it returns. Machines do not lob: straight. fn arrows(u: ui.Ui, body: Rect, t: f32, p: Plan, made: Recording.Syscall) void { - const x = theme.layout.state.x - theme.layout.program.x + 40; + // At the drawing's right, where it meets the state column the call leaves from. + const x = body.w - 56; const bottom = body.y + body.h; const reach = 64; // Off promptly, and settling in the kernel. @@ -298,6 +342,9 @@ fn what(nr: u16, kind: u8, arg: usize) []const u8 { } fn value(u: ui.Ui, made: Recording.Syscall, kind: u8, arg: usize, text_used: *bool) []const u8 { + // Flags and a mode are bits: hex, said so. + const meaning = what(made.nr, kind, arg); + if (std.mem.eql(u8, meaning, "flags") or std.mem.eql(u8, meaning, "mode")) return u.print("0x{x}", .{made.args[arg]}); const a = made.args[arg]; switch (kind) { 'i' => return u.print("{d}", .{@as(i32, @bitCast(@as(u32, @truncate(a))))}), @@ -305,7 +352,8 @@ fn value(u: ui.Ui, made: Recording.Syscall, kind: u8, arg: usize, text_used: *bo 's' => if (made.text.len > 0 and !text_used.*) { text_used.* = true; const base = std.fs.path.basename(made.text); - return u.print("\"{s}\"", .{base[0..@min(base.len, 14)]}); + // A string cut says so: `…` and no closing quote. + return if (base.len <= 14) u.print("\"{s}\"", .{base}) else u.print("\"{s}\u{2026}", .{base[0..13]}); }, else => {}, } @@ -373,10 +421,12 @@ pub const Timeline = struct { }; test "a crossing is as long as what the call does" { - // A call with no work: 3.7 s. Fifteen bytes copied up: 4.8. - try std.testing.expectApproxEqAbs(@as(f32, 3.70), Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }).total, 1e-3); + // A call with no work: 4.0 s. Fifteen bytes copied up: 5.1. + try std.testing.expectApproxEqAbs(@as(f32, 4.00), Plan.of(.{ .nr = 3, .args = @splat(0), .enter = 0 }).total, 1e-3); const read = Plan.of(.{ .nr = 0, .args = .{ 3, 0x1000, 32, 0, 0, 0 }, .enter = 0, .exit = 0, .result = 15 }); - try std.testing.expectApproxEqAbs(@as(f32, 4.77), read.total, 1e-2); + try std.testing.expectApproxEqAbs(@as(f32, 5.07), read.total, 1e-2); + // What came back is stored after it came back. + try std.testing.expect(read.stored > read.returns); // Nothing on the kernel's side before the arrow is through the line. try std.testing.expect(read.leaves >= read.enters and read.name >= read.enters + Plan.cross); try std.testing.expect(read.fills > read.name and read.returns > read.fills + 15 * Plan.byte); |
