diff options
Diffstat (limited to 'anim/src')
| -rw-r--r-- | anim/src/Recording.zig | 3 | ||||
| -rw-r--r-- | anim/src/array.zig | 26 | ||||
| -rw-r--r-- | anim/src/calls.zig | 6 | ||||
| -rw-r--r-- | anim/src/context.zig | 69 | ||||
| -rw-r--r-- | anim/src/cursor.zig | 153 | ||||
| -rw-r--r-- | anim/src/disasm.zig | 2 | ||||
| -rw-r--r-- | anim/src/hexdump.zig | 110 | ||||
| -rw-r--r-- | anim/src/map.zig | 5 | ||||
| -rw-r--r-- | anim/src/root.zig | 7 | ||||
| -rw-r--r-- | anim/src/rows.zig | 6 | ||||
| -rw-r--r-- | anim/src/syscalls.zig | 72 | ||||
| -rw-r--r-- | anim/src/ties.zig | 204 | ||||
| -rw-r--r-- | anim/src/ui.zig | 15 | ||||
| -rw-r--r-- | anim/src/words.zig | 29 |
14 files changed, 539 insertions, 168 deletions
diff --git a/anim/src/Recording.zig b/anim/src/Recording.zig index 1a4d859..a6e940c 100644 --- a/anim/src/Recording.zig +++ b/anim/src/Recording.zig @@ -820,7 +820,8 @@ pub fn drawn(r: *const Recording, span: Span, from: u64, to: u64) bool { } pub fn touches(list: []const Span, addr: u64, size: u64) bool { - for (list) |s| if (s.addr < addr + size and s.addr + s.len > addr) return true; + // Saturating: a register's chain asks about any value, to the top of the address space. + for (list) |s| if (s.addr < addr +| size and s.addr + s.len > addr) return true; return false; } diff --git a/anim/src/array.zig b/anim/src/array.zig index 8d53fb8..fad10c5 100644 --- a/anim/src/array.zig +++ b/anim/src/array.zig @@ -191,19 +191,23 @@ pub const Array = struct { // cell to cell as the idea strikes; two in one cell share its pin. var at_cell: [32]std.ArrayList([]const u8) = @splat(.empty); var slide: [32]?f32 = @splat(null); + // At a sprint the pins hold, and move only where a phrase ends: at the mark's moments. + const sprint = now.plan.gait == .sprint; + const pin_is = if (sprint) rec.moment(now.marks[1]) else now.moment(); + const pin_was = if (sprint) rec.moment(now.marks[0]) else now.before(); for (g.indices) |name| { - const iv = rec.variable(f.scratch, now.moment(), name) orelse continue; - const here = number(now.moment(), iv.addr, @min(iv.size, 8), true) orelse continue; + const iv = rec.variable(f.scratch, pin_is, name) orelse continue; + const here = number(pin_is, iv.addr, @min(iv.size, 8), true) orelse continue; if (here < 0 or here >= count) continue; const k: usize = @intCast(here); at_cell[k].append(f.scratch, name) catch {}; - if (number(now.before(), iv.addr, @min(iv.size, 8), true)) |was| if (was != here and was >= 0 and was < count) { + if (number(pin_was, iv.addr, @min(iv.size, 8), true)) |was| if (was != here and was >= 0 and was < count) { slide[k] = @floatFromInt(was); }; } // And the registers that hold a cell's address: a pin, where a link lands. - const is = (now.moment().regs(rec.tid) catch null) orelse @import("ztrace").Regs{}; - const was_regs = (now.before().regs(rec.tid) catch null) orelse is; + const is = (pin_is.regs(rec.tid) catch null) orelse @import("ztrace").Regs{}; + const was_regs = (pin_was.regs(rec.tid) catch null) orelse is; const ink = context.ink(context.regionOf(moment, v.addr)); for (&at_cell, 0..) |*names, k| { const addr = v.addr + k * elem; @@ -218,10 +222,20 @@ pub const Array = struct { const before = was_regs.named(name) == addr; const after = is.named(name) == addr; if (!before and !after) continue; - const s = ties.pinShows(now, i, .node); + const s = if (sprint) blk: { + const p = now.moving(.idea, 0, 0); + break :blk @TypeOf(ties.pinShows(now, i, .node)){ .old = 1 - p, .new = p }; + } else ties.pinShows(now, i, .node); const this = if (before and after) 1 else if (after) s.new else s.old; if (before != after and indices > 0) text = @min(text, @abs(2 * this - 1)); if (this < 0.5) continue; + // Under a sprint's veil the registers' names leave the cells (a cell's + // right name would print over the next cell's left), fading through its middle. + const veiled = now.sprint_veil; + if (veiled > 0) { + if (indices > 0) text = @min(text, @abs(2 * veiled - 1)) else shows = @min(shows, std.math.clamp(1 - 2 * veiled, 0, 1)); + } + if (veiled >= 0.5) continue; names.append(f.scratch, name) catch {}; if (indices == 0) shows = @min(shows, this); } diff --git a/anim/src/calls.zig b/anim/src/calls.zig index 9c3df04..50e83b2 100644 --- a/anim/src/calls.zig +++ b/anim/src/calls.zig @@ -134,8 +134,10 @@ pub const Tree = struct { } else u.faded(amount).label(.mono, size, cell, .center, words, t.primary); } if (active) continue; - // Done: what it returned, on its shoulder; struck as it lands. - const badge: Rect = .{ .x = c[0] + m.badge_at[0], .y = c[1] - m.badge_at[1], .w = m.badge, .h = m.badge }; + // Done: what it returned, on its outer shoulder (a left child's + // left, off its parent's disc); struck as it lands. + const left_child = if (n.parent) |p| n.x < nodes[p].x else false; + const badge: Rect = .{ .x = if (left_child) c[0] - m.badge_at[0] - m.badge else c[0] + m.badge_at[0], .y = c[1] - m.badge_at[1], .w = m.badge, .h = m.badge }; const heat: ui.Heat = if (n.call.exit.? > now.stops[1]) now.heat(0, null, since - time.badge_after) else .none; const ink = u.cellWritten(badge, heat, theme.color.page); // Framed, as every result is, but while the strike's paper is on it. diff --git a/anim/src/context.zig b/anim/src/context.zig index 37a95a6..9829fa7 100644 --- a/anim/src/context.zig +++ b/anim/src/context.zig @@ -46,6 +46,8 @@ pub const legend = blk: { /// window on the map and its place; its tags, rules and lanes how much shown. pub const Zoom = struct { box: Rect, to: Rect, chrome: f32 }; pub var zoomed: [8]?Zoom = @splat(null); +/// How much the thread shows: it fades in (12 f) once a dive has landed, never in a frame. +pub var thread_shows: f32 = 1; /// A panel's `Ui`, moved to where the stage has its box now (or, in a /// dive, scaled into the rect it is on its way through). @@ -161,6 +163,7 @@ pub const Registers = struct { var marks: rows.Marks = .{}; var landed = now.landed(.cpu, 0); var note: []const u8 = ""; + var note_shows: f32 = 1; const crossing: ?Recording.Syscall = if (r.syscalls) syscalls.inStep(now) else null; // A register is framed as carrying the call only while it holds the // argument in the moment shown: the stop before the call, until the @@ -176,6 +179,8 @@ pub const Registers = struct { // A descriptor says what it is open on: the `value` class `fd`. const names = zt.syscalls.names(made.nr); if (k <= names.len and std.mem.endsWith(u8, names[k - 1], "fd")) note = rec.openOn(u.f.scratch, value_was, made.enter); + // In with its framing, over 12 f, and out with it: never in a frame. + note_shows = @min(std.math.clamp(framed / time.quick, 0, 1), now.reading(.cpu, 0)); }; if (if (std.mem.eql(u8, name, "rax")) crossing else null) |made| { // rax: what was there, then the result, once the kernel's rows @@ -210,8 +215,15 @@ pub const Registers = struct { // At a run a value changes in place under an 8 f crossfade, unmarked, never in a frame. const ran = runFade(now, .cpu); if (ran < 1 and value_was != value_now) _ = rows.reg(u.faded(1 - ran), y, w, name, was.moment, value_was, marks); - const hops = rows.reg(if (ran < 1 and value_was != value_now) u.faded(ran) else u, y, w, name, if (landed or ran < 1) is.moment else was.moment, if (landed or ran < 1) value_now else value_was, marks); - fdNote(u, hops, y, note); + // Its chain reads memory as the panels show it: what the step writes + // there is followed again (`extend`) once the bytes have landed, never before. + var memory = if (landed or ran < 1) is.moment else was.moment; + if (ran >= 1 and landed and !r.quiet) { + memory, const again, marks.hops = now.following(value_now); + if (again) |ago| marks.extend = @min(marks.extend orelse ago, ago); + } + const hops = rows.reg(if (ran < 1 and value_was != value_now) u.faded(ran) else u, y, w, name, memory, if (landed or ran < 1) value_now else value_was, marks); + fdNote(u.faded(note_shows), hops, y, note); anchor(u, i, hops, y); } @@ -349,12 +361,16 @@ pub const Stack = struct { // stop deeper or shallower than a call is) does not scroll: the old // rows fade out before memory strikes and the new ones in after, // each with the memory of its own stop. - const landed = now.landed(.memory, 0); const jumped = far(window[0], window[1], slots); + // Out over 12 f to memory's landing and in over 12 f (at a run, half + // its step each, the turn no sooner than that): never in a frame. + const fade = @min(time.quick, now.plan.total / 2.0); + const turn = @max(now.plan.at[1] + time.strike.in / 2.0, fade); + const landed = if (jumped and !now.resting()) now.time >= turn else now.landed(.memory, 0); // On the minimap the window glides there, whether it scrolls or fades here. const ways = window; const since_memory = now.since(.memory, 0); - const jump_shows: f32 = if (!jumped or now.resting()) 1 else if (!landed) 1 - std.math.clamp((since_memory + time.quick) / time.quick, 0, 1) else std.math.clamp((since_memory - time.strike.in / 2.0) / time.quick, 0, 1); + const jump_shows: f32 = if (!jumped or now.resting()) 1 else if (!landed) 1 - std.math.clamp((now.time - turn + fade) / fade, 0, 1) else std.math.clamp((now.time - turn) / fade, 0, 1); if (jumped) window = if (landed) .{ window[0], window[0] } else .{ window[1], window[1] }; const v = u.faded(jump_shows); // Going to the hold and coming from it, the rows scroll: the @@ -476,16 +492,19 @@ pub const Stack = struct { const rsp_shown = if (landed) is.rsp else was.rsp; // What each word is, where the recording says (`zt.telescope.slots`): // a register saved for the caller, a local, the process's first stack. - const roles_from = window[0] -% 16; + // Of the rows of both windows: those sliding out keep theirs as they go. + const roles_from = @min(window[0], window[1]) -% 16; + const roles_n = slots + 4 + @abs(@as(i64, @bitCast(window[0] -% window[1]))) / 8; // Before the step and after it: a role that changes crossfades as memory strikes (12 f). var roles_buf: [2][80]zt.telescope.Slot = undefined; const roles = [2][]zt.telescope.Slot{ - zt.telescope.slots(now.before(), &was, roles_from, roles_buf[0][0..@min(slots + 4, roles_buf[0].len)]) catch roles_buf[0][0..0], - zt.telescope.slots(now.moment(), &is, roles_from, roles_buf[1][0..@min(slots + 4, roles_buf[1].len)]) catch roles_buf[1][0..0], + zt.telescope.slots(now.before(), &was, roles_from, roles_buf[0][0..@min(roles_n, roles_buf[0].len)]) catch roles_buf[0][0..0], + zt.telescope.slots(now.moment(), &is, roles_from, roles_buf[1][0..@min(roles_n, roles_buf[1].len)]) catch roles_buf[1][0..0], }; // The words that point at other words of the window: `arc`s. var at_rows: std.ArrayList(hexdump.RowAt) = .empty; - var pointers: std.ArrayList(struct { hexdump.RowAt, bool }) = .empty; + // Each with whether it is a saved rbp before the step and after it. + var pointers: std.ArrayList(struct { hexdump.RowAt, [2]bool }) = .empty; var n: i64 = @as(i64, @intFromFloat(@floor(-slide))) - 1; while (n <= @as(i64, @intCast(slots)) - @as(i64, @intFromFloat(@floor(slide)))) : (n += 1) { const y = top + (@as(f32, @floatFromInt(n)) + slide) * m.row; @@ -501,10 +520,13 @@ pub const Stack = struct { const below_rsp: i64 = @bitCast(addr -% if (held) rsp_shown else is.rsp); map.row(.stack, addr, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row }); // `free`: above rsp, not yet reached: its address at 60%, its word faint. - if (held and addr < rsp_shown) { - rows.free(v, y, memory, addr, below_rsp, lead); - continue; - } + // A free word rsp reaches (a push, `sub rsp`) becomes a slot as memory strikes (12 f), never in a frame. + const free_was = held and addr < was.rsp; + const free_is = held and addr < is.rsp; + const slot_shows: f32 = if (free_was == free_is or now.resting()) @as(f32, if (free_is) 0 else 1) else if (free_is) 1 - recast else recast; + if (slot_shows < 1) rows.free(v.faded(1 - slot_shows), y, memory, addr, below_rsp, lead); + if (slot_shows <= 0) continue; + const vs = v.faded(slot_shows); // A frame's name beside this row: the chain ends a character before it. var room_w = box.w; for (spans[0..n_spans]) |sp| { @@ -518,7 +540,7 @@ pub const Stack = struct { gap = share * (u.width(.mono, size, name) + ui.advance(size)); } const gapped = gap > 0 and names.names.len > 0 and names.shows > 0; - if (gapped) pinGap(v.faded(names.shows), y, names.names, lone.?, gap); + if (gapped) pinGap(vs.faded(names.shows), y, names.names, lone.?, gap); const k_role = (addr -% roles_from) / 8; var role_at: [2]@TypeOf(roleName(u, .none, 0)) = undefined; for (&role_at, roles, [2]Recording.Moment{ now.before(), now.moment() }) |*r, of, mem| { @@ -533,10 +555,12 @@ pub const Stack = struct { const word_was = Recording.word(now.before(), addr, 8) catch null; const word_is = Recording.word(now.moment(), addr, 8) catch null; const fades = ran < 1 and !std.meta.eql(word_was, word_is); - if (fades) _ = rows.slot(v.faded(1 - ran), y, room_w, now.before(), addr, below_rsp, &.{}, 0, marks, role.name, role.local, role_was); - const hops = rows.slot(if (fades) v.faded(ran) else v, y, room_w, if (fades) now.moment() else now.shownAt(addr), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local, role_was); - at_rows.append(u.f.scratch, .{ .addr = addr, .y = y }) catch {}; - pointers.append(u.f.scratch, .{ .{ .addr = addr, .y = y }, what == .saved and std.mem.eql(u8, what.saved, "rbp") }) catch {}; + if (fades) _ = rows.slot(vs.faded(1 - ran), y, room_w, now.before(), addr, below_rsp, &.{}, 0, marks, role.name, role.local, role_was); + const hops = rows.slot(if (fades) vs.faded(ran) else vs, y, room_w, if (fades) now.moment() else now.shownAt(addr, 8), addr, below_rsp, if (gapped) &.{} else names.names, names.shows, marks, role.name, role.local, role_was); + // An arc's ends are rows on show (the row above the window, there for a slide, is not). + if (y + m.row > top + 1 and y < box.h - m.pad - 1) at_rows.append(u.f.scratch, .{ .addr = addr, .y = y }) catch {}; + const what_was: zt.telescope.Role = if (k_role < roles[0].len) roles[0][k_role].role else .none; + if (y + m.row > top + 1 and y < box.h - m.pad - 1) pointers.append(u.f.scratch, .{ .{ .addr = addr, .y = y }, .{ what_was == .saved and std.mem.eql(u8, what_was.saved, "rbp"), what == .saved and std.mem.eql(u8, what.saved, "rbp") } }) catch {}; // Only a row on show is a place a tie can land. if (y >= top - 1 and y + m.row <= box.h - m.pad + 1) { ties.anchor(u, .{ .word = addr }, .{ .x = theme.metric.slot.address, .y = y, .w = if (hops.n > 0) hops.x[0] + hops.w[0] - theme.metric.slot.address else 120, .h = m.row }); @@ -547,12 +571,17 @@ pub const Stack = struct { // A frame's saved rbp is drawn by its span: its arc only in a step that touches it. var arcs: rows.Arcs = .{}; for (pointers.items) |p_| { - const word, const saved = p_; - if (saved and !(now.writeAge(word.addr, 8) == 0 or now.wasRead(word.addr, 8))) continue; + const word, const saved_was = p_; + const saved = saved_was[1]; + const touched = now.writeAge(word.addr, 8) == 0 or now.wasRead(word.addr, 8); + if (saved and saved_was[0] and !touched) continue; const before = arcs.n; hexdump.pointerArcs(&arcs, now, word.addr, word.y, at_rows.items, 8, .{ top - m.pad, box.h - m.pad }, false, false); + if (arcs.n == before) continue; // Its step's alone: it goes with the advance (18 f), not in the next step's first frame. - if (saved and arcs.n > before) arcs.items[before].shows *= 1 - std.math.clamp((now.time - now.plan.advance) / time.read.out, 0, 1); + if (saved and touched) arcs.items[before].shows *= 1 - std.math.clamp((now.time - now.plan.advance) / time.read.out, 0, 1); + // A word becoming a saved rbp, or no longer one, with the step: its arc goes or comes as its role does (12 f). + if (!touched and saved != saved_was[0]) arcs.items[before].shows *= if (saved) 1 - recast else recast; } arcs.draw(v, theme.metric.arc.stack_lanes); // Where the window is, for a link to a word outside it. diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index 2811488..f0f90ff 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -84,6 +84,10 @@ pub const Plan = struct { /// The line fires (not on a step that goes on from the last one's /// mark: a crossing stepped over, from its call row). fires: bool = true, + /// Seconds of the step before's cool still to run at this one's start + /// (a step that went on from it without its rest: a crossing from its + /// call row): what it struck goes on cooling, never cut in a frame. + cooling: f32 = 0, /// Once the pattern is known: the levels a stagger apart from the /// first frame, the mark after them, in `seconds`. @@ -91,8 +95,9 @@ pub const Plan = struct { return .{ .gait = .run, .at = .{ 0, time.stagger, 2 * time.stagger }, .advance = time.run_ease, .travel = time.run_ease, .total = seconds }; } + /// The mark, seen only where a phrase ends, moves over the step there: never in a frame. pub fn sprinting(seconds: f32) Plan { - return .{ .gait = .sprint, .at = @splat(0), .advance = 0, .travel = 0, .total = seconds }; + return .{ .gait = .sprint, .at = @splat(0), .advance = 0, .travel = seconds, .total = seconds }; } }; @@ -115,7 +120,7 @@ pub const Cursor = struct { /// 0 to 1 through the step it is taking; 1 at rest. phase: anim.Value, /// The step's `Plan`, a value a field. - plan: [9]anim.Value, + plan: [10]anim.Value, /// The moment the current mark was on, and the one it is on (or going to). marks: [2]anim.Value, /// 1 while steps are hurried (the head counts them), and while what @@ -147,7 +152,7 @@ pub const Cursor = struct { .stops = undefined, .gaits = undefined, .phase = s.value(1), - .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1) }, + .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1), s.value(0) }, .marks = .{ s.value(here), s.value(here) }, .hurried = s.value(0), .veil = s.value(0), @@ -176,7 +181,7 @@ pub const Cursor = struct { stops: [history]anim.Value, gaits: [history]anim.Value, phase: anim.Value, - plan: [9]anim.Value, + plan: [10]anim.Value, marks: [2]anim.Value, hurried: anim.Value, veil: anim.Value, @@ -253,24 +258,24 @@ pub const Cursor = struct { const Step = struct { stops: [history]f32, gaits: [history]f32, - plan: [9]f32, + plan: [10]f32, marks: [2]f32, count: f32, seconds: f32, fn run(st: @This(), sf: *anim.Frame, v: Cursor) void { - var set: [2 * history + 13]anim.Animation = undefined; + var set: [2 * history + 14]anim.Animation = undefined; for (v.stops, st.stops, 0..) |value, is, i| set[i] = value.to(is); - for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 13 + i] = value.to(is); + for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 14 + i] = value.to(is); for (v.plan, st.plan, history..) |value, is, n| set[n] = value.to(is); - set[history + 9] = v.marks[0].to(st.marks[0]); - set[history + 10] = v.marks[1].to(st.marks[1]); - set[history + 11] = v.phase.to(0); - set[history + 12] = v.count.to(st.count); + set[history + 10] = v.marks[0].to(st.marks[0]); + set[history + 11] = v.marks[1].to(st.marks[1]); + set[history + 12] = v.phase.to(0); + set[history + 13] = v.count.to(st.count); sf.play(set, .{ .seconds = 0 }); sf.play(.{v.phase.to(1)}, .{ .seconds = st.seconds, .ease = anim.ease.linear }); } }; - var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)) }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds }; + var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)), plan.cooling }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds }; st.stops[0] = @floatFromInt(to); for (1..history) |i| st.stops[i] = settled(s, c.stops[i - 1]); st.gaits[0] = @floatFromInt(@intFromEnum(plan.gait)); @@ -329,10 +334,15 @@ pub const Cursor = struct { const regs: f32 = @floatFromInt(@popCount(rec.registersChanged(from, to) & ~quiet)); // Memory gives up its slot when nothing it touched is drawn. var wrote_n: usize = 0; - for (rec.written(from, to)) |span| wrote_n += @intFromBool(rec.drawn(span, from, to)); + var strikes_n: usize = 0; + for (rec.written(from, to)) |span| { + wrote_n += @intFromBool(rec.drawn(span, from, to)); + strikes_n += @intFromBool(takesPlace(rec, span, from, to)); + } var read_n: usize = 0; for (rec.read(from, to)) |span| read_n += @intFromBool(rec.drawn(span, from, to)); - const wrote: f32 = @floatFromInt(wrote_n); + // As many strikes as writes take a place (`takesPlace`): the last is 6 f a write after the first. + const wrote: f32 = @floatFromInt(if (wrote_n > 0) @max(strikes_n, 1) else 0); const touched = wrote_n > 0 or read_n > 0; const deeper = rec.depths[to] > rec.depths[from]; const back = rec.depths[to] < rec.depths[from]; @@ -485,6 +495,7 @@ pub const Cursor = struct { .total = placed.value(c.plan[6]), .wave = placed.value(c.plan[7]) >= 0.5, .fires = placed.value(c.plan[8]) >= 0.5, + .cooling = placed.value(c.plan[9]), }, .marks = .{ whole(rec, placed.value(c.marks[0])), whole(rec, placed.value(c.marks[1])) }, .hurried = placed.value(c.hurried), @@ -510,6 +521,13 @@ pub const Cursor = struct { } }; +/// Whether a write of the step from `from` to `to` takes a place among +/// its strikes: not on a stack frame the step has already left (a callee's +/// words, under rsp, that no window shows: `Recording.drawn`). +fn takesPlace(rec: *const Recording, span: Recording.Span, from: u64, to: u64) bool { + return rec.drawn(span, from, to) or zt.telescope.region(rec.moment(to), span.addr) catch .none != .stack; +} + fn whole(rec: *const Recording, value: f32) u64 { return @min(@as(u64, @intFromFloat(@max(value, 0))), rec.end()); } @@ -671,7 +689,9 @@ pub const Now = struct { n.rec.moment(n.stops[age]).read(addr, is[0..l], known_is[0..l]) catch return null; var out: ?[2]u8 = null; for (0..l) |i| if (known_was[i] and known_is[i] and was[i] != is[i]) { - out = .{ if (out) |o| o[0] else @intCast(i), @intCast(i) }; + // Its first apart: assigned in one expression, `out` would be read as it is written. + const first: u8 = if (out) |o| o[0] else @intCast(i); + out = .{ first, @intCast(i) }; }; return out; } @@ -718,6 +738,8 @@ pub const Now = struct { if (a == 0 or a > s.ember_steps) return .none; // A run changes values unmarked: it shows them settled. if (n.gaits[a] == .run) return .none; + // The step before went on into this one before its cool was done: it cools on. + if (a == 1 and n.plan.cooling > 0 and n.gaits[1] == .walk and !n.resting() and n.time < n.plan.cooling) return cooled(1 - (n.plan.cooling - n.time) / s.cool, .nothing, 0); if (a < s.ember_steps) return .ember; // Linear: a fade, as the mark leaves: secondary action does not // start on the fire's frame, where the step's primary one does. @@ -753,17 +775,23 @@ pub const Now = struct { if (since_strike >= -s.arm) armed.arm = std.math.clamp((since_strike + s.arm) / time.stagger, 0, 1); return armed; } - const cooled = (n.time - n.plan.advance) / s.cool; const in = std.math.clamp(since_strike / s.in, 0, 1); + var h = cooled((n.time - n.plan.advance) / s.cool, if (was.level >= 1) .ember else .nothing, if (was.level >= 1) 1 - in else 0); + h.in = in; + h.out = if (since_strike < s.pulse) theme.pulse(since_strike / s.pulse) else 0; + return h; + } + + /// A struck thing `cooled` of the way through its cool (0 to 1): the + /// paper going on `glide`; the turned corner coming in over the cool's + /// last 6 f (and the old one, `corner_was`, going as a strike comes in over it). + fn cooled(p: f32, from: @FieldType(ui.Heat, "from"), corner_was: f32) ui.Heat { + const s = time.strike; return .{ .level = 1, - .solid = 1 - glide(std.math.clamp(cooled, 0, 1)), - .in = in, - .from = if (was.level >= 1) .ember else .nothing, - .out = if (since_strike < s.pulse) theme.pulse(since_strike / s.pulse) else 0, - // The turned corner: the old one goes as the paper comes in over - // it; the new one comes in over the cool's last 6 f. - .corner = @max(std.math.clamp((cooled - 1) * s.cool / s.corner + 1, 0, 1), if (was.level >= 1) 1 - in else 0), + .solid = 1 - glide(std.math.clamp(p, 0, 1)), + .from = from, + .corner = @max(std.math.clamp((p - 1) * s.cool / s.corner + 1, 0, 1), corner_was), }; } @@ -771,13 +799,33 @@ pub const Now = struct { /// `level`, `delay` seconds after its first, and 6 f after the write of /// this step before theirs. pub fn written(n: Now, addr: u64, size: u64, level: Level, delay: f32) ui.Heat { + var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.sinceStrike(addr, size, level, delay)); // What the kernel fills in a crossing lands as its work does it, unpulsed. - if (level == .memory) if (syscalls.filledAt(n, addr)) |at| { - var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.time - at); - h.out = 0; - return h; + if (level == .memory and syscalls.filledAt(n, addr) != null) h.out = 0; + return h; + } + + /// Seconds since the strike of `addr .. addr + size` with `level`, + /// `delay` after its first and 6 f after the write of this step before + /// theirs; what the kernel fills in a crossing, as its work lands it. + fn sinceStrike(n: Now, addr: u64, size: u64, level: Level, delay: f32) f32 { + if (level == .memory) if (syscalls.filledAt(n, addr)) |at| return n.time - at; + return n.since(level, delay + n.writeDelay(addr, size)); + } + + /// Seconds since this step's write of `addr .. addr + size` struck in + /// memory, at a walk; null where the step did not write it, or at + /// another pace. Until `in / 2` after it (s+3) the old value stands, + /// through the arm (`shownAt`, a dump's runs, a chain's hops). + pub fn struckAgo(n: Now, addr: u64, size: u64) ?f32 { + if (!n.walking() or n.writeAge(addr, size) != 0) return null; + // What the kernel fills, a byte every 2 f: the value is there once its last byte is. + var last: ?f32 = null; + for (0..size) |i| if (syscalls.filledAt(n, addr + i)) |at| { + last = @max(last orelse at, at); }; - return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size))); + if (last) |at| return n.time - at; + return n.sinceStrike(addr, size, .memory, 0); } /// `written`, struck `since` seconds ago (a loupe's own times: it strikes once it has opened). @@ -785,11 +833,44 @@ pub const Now = struct { return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), struck); } - /// The state to draw the memory at `addr` from: `shown(.memory)`, but - /// what the kernel fills in a crossing from when its byte lands. - pub fn shownAt(n: Now, addr: u64) Recording.Moment { - if (syscalls.filledAt(n, addr)) |at| return if (n.time - at >= time.strike.in / 2.0) n.moment() else n.before(); - return n.shown(.memory); + /// The state to draw the memory at `addr .. addr + size` from: + /// `shown(.memory)`, but a write of this step from its own strike + /// (s+3), never before its arm; what the kernel fills in a crossing + /// from when its byte lands. + pub fn shownAt(n: Now, addr: u64, size: u64) Recording.Moment { + return if (n.landedAt(addr, size)) n.moment() else n.before(); + } + + /// Whether memory at `addr .. addr + size` shows the step's state (`shownAt`). + pub fn landedAt(n: Now, addr: u64, size: u64) bool { + if (n.struckAgo(addr, size)) |ago| return ago >= time.strike.in / 2.0; + return n.landed(.memory, 0); + } + + /// The memory a chain from `value` (a register's, struck or not) reads + /// as the panels show it (`shownAt`: the word it points at, from its + /// strike), and, where the step changes what the chain says, seconds + /// since its hops are followed again (`extend`): 4 f after the bytes + /// land, never before. Null where the chain did not change. + /// Before the bytes land, from their strike, the hops it shows fade out + /// (the third: how much they show), so that none goes in a frame. + pub fn following(n: Now, value: u64) struct { Recording.Moment, ?f32, f32 } { + const memory = n.shownAt(value, 8); + if (!n.walking()) return .{ memory, null, 1 }; + const struck = n.struckAgo(value, 8) orelse n.since(.memory, 0); + const land = time.strike.in / 2.0; + // Followed again only while that shows (its hops 4 f apart, 6 f each). + if (struck < 0 or struck > land + 0.5) return .{ memory, null, 1 }; + var bufs: [2][6]zt.telescope.Link = undefined; + var texts: [2][48]u8 = undefined; + const was = zt.telescope.chase(n.before(), value, &bufs[0], &texts[0]) catch return .{ memory, null, 1 }; + const is = zt.telescope.chase(n.moment(), value, &bufs[1], &texts[1]) catch return .{ memory, null, 1 }; + const same = was.len == is.len and for (was, is) |a, b| { + if (a.value != b.value or !std.mem.eql(u8, a.text, b.text)) break false; + } else true; + if (same) return .{ memory, null, 1 }; + if (!n.landedAt(value, 8)) return .{ memory, null, 1 - std.math.clamp(struck / land, 0, 1) }; + return .{ memory, struck - 4.0 / 60.0, 1 }; } /// `written`, on a thing the viewer has watched only through the steps @@ -805,9 +886,9 @@ pub const Now = struct { var order: f32 = 0; var last: ?u64 = null; for (n.rec.written(n.stops[1], n.stops[0])) |span| { - if (span.addr < addr + size and span.addr + span.len > addr) return @min(order, 3) * write_apart; - // The kernel's own writes have their own times (`filledAt`). - if (syscalls.filledAt(n, span.addr) != null) continue; + if (span.addr < addr +| size and span.addr + span.len > addr) return @min(order, 3) * write_apart; + // The kernel's own writes have their own times (`filledAt`); a frame the step has left takes no place. + if (syscalls.filledAt(n, span.addr) != null or !takesPlace(n.rec, span, n.stops[1], n.stops[0])) continue; // Bytes of one write (one store, in pieces) are one strike. if (last == null or span.addr != last.?) order += 1; last = span.addr + span.len; diff --git a/anim/src/disasm.zig b/anim/src/disasm.zig index cf16c6a..4324b42 100644 --- a/anim/src/disasm.zig +++ b/anim/src/disasm.zig @@ -434,7 +434,7 @@ pub const Disasm = struct { marks.read_shows = now.reading(.memory, 0); } if (writes) if (after) |aa| { - if (state == .ran or now.landed(.memory, 0)) shown = rec.moment(aa); + if (state == .ran or now.landedAt(touch.addr, touch.len)) shown = rec.moment(aa); if (in_step) { marks.changed = 1; marks.changed_heat = now.written(touch.addr, touch.len, .memory, 0); diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index 47283e7..21db91f 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -65,6 +65,8 @@ pub const Of = struct { things: []const objects.Object = &.{}, array: ?struct { addr: u64, len: u64, elem: u8, type: ?Recording.types.Type = null } = null, region: u24 = theme.color.region.heap, + /// A lens's view: a row a register points into carries its pin (`rowPin`). + pins: bool = false, }; /// The band's view of bytes: its own panel over the state column, the @@ -106,6 +108,7 @@ pub const Dump = struct { if (v.rows == 0) return; const now = d.cursor.now(placed); var of = d.of; + of.pins = true; of.watched = 0; while (of.watched + 1 < now.stops.len and now.stops[of.watched + 1] >= d.since) of.watched += 1; var shows: [8]f32 = @splat(0); @@ -151,7 +154,9 @@ pub const View = struct { /// always, with `loud`: a loupe's). `rule`: the panel's top and bottom, /// where a stub to a row past the window ends. pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of) void { - drawArcs(u, now, x, y, first, count, of, false, .{ y - m.pad, y + @as(f32, @floatFromInt(count)) * m.row + m.pad }); + var view = of; + view.pins = true; + drawArcs(u, now, x, y, first, count, view, false, .{ y - m.pad, y + @as(f32, @floatFromInt(count)) * m.row + m.pad }); } pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize, of: Of, loud: bool, rule: [2]f32) void { @@ -174,6 +179,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u moment.read(addr, &values, &known) catch return; var runs: [16]rows.Run = undefined; var readings: [16]Field = undefined; + var keeps: [16]bool = @splat(false); var n: usize = 0; var holds_drawn = false; var at: u64 = 0; @@ -206,6 +212,7 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u } run.heat = now.written(here, run.len, .memory, 0); run.changed = now.changedBytes(here, run.len); + if (now.struckAgo(here, run.len)) |ago| keeps[n] = ago < theme.time.strike.in / 2.0; if (now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) run.read = now.reading(.memory, 0); if (run.kind == .number or run.kind == .pointer) ties.anchor(v, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = ry, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); readings[n] = .{ .at = run.first, .len = run.len, .reads = switch (run.kind) { @@ -218,9 +225,11 @@ pub fn drawArcs(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: u at += run.len; } @import("map.zig").row(.view, addr, v, .{ .x = 0, .y = ry, .w = theme.layout.state.w, .h = m.row }); + keepOld(now, addr, &values, &known, runs[0..n], keeps[0..n]); rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift); if (pass + 1 == passes.n) for (runs[0..n]) |run| if (run.kind == .pointer and run.len == 8) pointerArcs(&arcs, now, addr + run.first, ry, shown_rows, 16, rule, loud, false); - const end = reading(v, ry, shift, moment, &values, &known, readings[0..n]); + const room = if (!of.pins) full_room else if (pass == 0) rowPin(dump, now, addr, ry) else rowPinRoom(dump, now, addr); + const end = readingIn(v, ry, shift, moment, &values, &known, readings[0..n], room); // The size word of the chunk after: malloc's, a note after the reading. const last = runs[n - 1]; if (last.kind == .loose and last.first == 8 and last.len == 8 and std.mem.indexOfScalar(bool, known[8..], false) == null and chunkAfter(moment, addr + 8)) { @@ -263,6 +272,65 @@ fn rowPasses(now: cursors.Now, addr: u64) Passes { return plain; } +/// The registers whose value is in the row `addr .. addr + 16`, as a step +/// moves them (`ties.pinShows`: a name joining or leaving fades through the +/// middle of its change), in pwndbg's order: a view's row a register points +/// into carries its pin, at the row's end (`Ui.pinEnd`). Draws it and +/// returns where the reading must end; publishes the row as a link's +/// target (`dump_pin`), its left edge. +fn rowPin(u: ui.Ui, now: cursors.Now, addr: u64, y: f32) f32 { + ties.anchor(u, .{ .dump_pin = addr }, .{ .x = 0, .y = y, .w = b.bracket, .h = m.row }); + const at = pinned(u, now, addr); + if (at.names.len == 0 or at.shows <= 0) return full_room; + const x = u.faded(at.shows).pinEnd(full_room, y, at.names, rows.ink(rows.regionOf(now.moment(), addr))); + return x - adv; +} + +/// Where the reading of a row must end for its pin (`rowPin`), not drawing it. +fn rowPinRoom(u: ui.Ui, now: cursors.Now, addr: u64) f32 { + const at = pinned(u, now, addr); + if (at.names.len == 0 or at.shows <= 0) return full_room; + const p = theme.metric.pin; + var shown: []const u8 = ""; + for (at.names[0..@min(at.names.len, 3)], 0..) |name, i| shown = if (i == 0) name else u.print("{s} {s}", .{ shown, name }); + if (at.names.len > 3) shown = u.print("{s} +{d}", .{ shown, at.names.len - 3 }); + return full_room - u.width(.mono, theme.size.mono.context, shown) - p.row_gap - p.row_head[0] - adv; +} + +fn pinned(u: ui.Ui, now: cursors.Now, addr: u64) struct { names: []const []const u8, shows: f32 } { + const rec = now.rec; + const context = @import("context.zig"); + const is = (now.moment().regs(rec.tid) catch null) orelse return .{ .names = &.{}, .shows = 0 }; + const was = (now.before().regs(rec.tid) catch null) orelse is; + var names: std.ArrayList([]const u8) = .empty; + var shows: f32 = 1; + for (theme.metric.all_registers[0..16]) |name| { + const in_was = if (was.named(name)) |v| v >= addr and v < addr + 16 else false; + const in_is = if (is.named(name)) |v| v >= addr and v < addr + 16 else false; + if (!in_was and !in_is) continue; + const s = ties.pinShows(now, context.index(name).?, .node); + const this: f32 = if (in_was and in_is) 1 else if (in_is) s.new else s.old; + if (in_was != in_is) shows = @min(shows, @abs(2 * this - 1)); + if (this < 0.5) continue; + names.append(u.f.scratch, name) catch break; + } + return .{ .names = names.items, .shows = shows }; +} + +/// The runs this step writes whose strike has not landed (`keeps`) keep +/// the bytes they had: the digits and the reading change at s+3, as the +/// fill comes in, never before the arm. +fn keepOld(now: cursors.Now, addr: u64, values: *[16]u8, known: *[16]bool, runs: []const rows.Run, keeps: []const bool) void { + if (std.mem.indexOfScalar(bool, keeps, true) == null) return; + var was: [16]u8 = undefined; + var known_was: [16]bool = undefined; + now.before().read(addr, &was, &known_was) catch return; + for (runs, keeps) |run, old| if (old) { + @memcpy(values[run.first..][0..run.len], was[run.first..][0..run.len]); + @memcpy(known[run.first..][0..run.len], known_was[run.first..][0..run.len]); + }; +} + /// A row of a panel: its first byte's address and its top. pub const RowAt = struct { addr: u64, y: f32 }; @@ -400,6 +468,11 @@ pub const Fields = struct { /// Seconds since its strikes began, a field 6 f after the one before /// (a loupe's, once it has opened); null: memory's slot. struck: ?f32 = null, + /// A view: a row a register points into carries its pin (`rowPin`). + pins: bool = false, + /// The fields before the step, where it retypes them: a run whose strike + /// has not landed is read as what it was. + was: []const Field = &.{}, }; /// The region's rows in view `v`, from `y`, sixteen bytes a row from its @@ -440,7 +513,8 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { } last = r; const passes = rowPasses(now, of.base + 16 * r); - for (passes.moments[0..passes.n], passes.shows[0..passes.n]) |mm, shows| fieldRow(u.faded(shows), now, ry, of.base + 16 * r, if (passes.n == 2) mm else moment, of, lead, shift); + const room = if (of.pins) rowPin(u, now, of.base + 16 * r, ry) else full_room; + for (passes.moments[0..passes.n], passes.shows[0..passes.n]) |mm, shows| fieldRow(u.faded(shows), now, ry, of.base + 16 * r, if (passes.n == 2) mm else moment, of, lead, shift, room); at_rows.append(u.f.scratch, .{ .addr = of.base + 16 * r, .y = ry }) catch {}; @import("map.zig").row(.view, of.base + 16 * r, u, .{ .x = 0, .y = ry, .w = 860, .h = m.row }); ry += m.row; @@ -509,7 +583,7 @@ fn focus(now: cursors.Now, of: Fields, rs: []const u64) usize { return 0; } -fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize, shift: f32) void { +fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Moment, of: Fields, lead: usize, shift: f32, room: f32) void { var values: [16]u8 = undefined; var known: [16]bool = undefined; moment.read(addr, &values, &known) catch return; @@ -537,6 +611,7 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom }; var runs: [16]rows.Run = undefined; var readings: [16]Field = undefined; + var keeps: [16]bool = @splat(false); var n: usize = 0; var at: u8 = 0; while (at < 16 and addr + at < of.base + of.len) { @@ -558,6 +633,9 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom }; run.heat = now.writtenWatched(here, run.len, .memory, 0, 0, of.watched); run.changed = now.changedBytes(here, run.len); + // Until its own strike lands the old value stands: the loupe's own times, or memory's. + const ago = if (of.struck) |since| (if (now.walking() and now.writeAge(here, run.len) == 0) since - @as(f32, @floatFromInt(field_k)) * cursors.write_apart else null) else if (of.watched > 0) now.struckAgo(here, run.len) else null; + if (ago) |a| keeps[n] = a < theme.time.strike.in / 2.0; if (of.struck) |since| run.heat = now.writtenAt(here, run.len, since - @as(f32, @floatFromInt(field_k)) * cursors.write_apart); // What the kernel fills lands a byte every 2 f. if (@import("syscalls.zig").filledAt(now, here) != null) run.apart = 2; @@ -568,6 +646,16 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom if (of.watched > 0 and now.wasRead(here, run.len) and now.writeAge(here, run.len) != 0) framed = @max(framed, now.reading(.memory, 0)); run.read = framed; readings[n] = .{ .at = at, .len = run.len, .reads = fl.reads, .big = fl.big, .type = fl.type, .note = fl.note, .addr = here }; + // Its old bytes read as what they were until its strike lands (the step retypes the field: malloc's). + if (keeps[n]) for (of.was) |old| if (of.base + old.at <= here and here < of.base + old.at + old.len) { + readings[n] = .{ .at = at, .len = run.len, .reads = old.reads, .big = old.big, .type = old.type, .note = old.note, .addr = here }; + run.kind = switch (old.reads) { + .number, .bytes, .size, .protected => .number, + .pointer => .pointer, + .text => .text, + }; + break; + }; ties.anchor(u, .{ .dump_run = here }, .{ .x = shift + rows.byteX(run.first) - 4, .y = y, .w = rows.byteX(run.first + run.len - 1) + 28 - rows.byteX(run.first) + 4, .h = m.row }); } else { // Up to the next field, or the row's end. @@ -582,16 +670,17 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom n += 1; at += run.len; } + keepOld(now, addr, &values, &known, runs[0..n], keeps[0..n]); // The kernel reading them: one frame round what it took of the row. if (gives and of.read > 0) u.faded(of.read).frame(.{ .x = shift + rows.byteX(given_from) - 7, .y = y - 1, .w = rows.byteX(given_to) - rows.byteX(given_from) + 38, .h = m.row + 2 }, theme.mark(.read).solid, 2); const shows = if (of.given) |g| g.shows else 0; if (gives and shows > 0) { if (shows < 1) rows.bytesAt(u.faded(1 - shows), y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift); rows.bytesAt(u.faded(shows), y, addr, &given_values, &given_known, runs[0..n], of.region, lead, true, moment, shift); - _ = reading(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n]); + _ = readingIn(u.faded(shows), y, shift, moment, &given_values, &given_known, readings[0..n], room); } else { rows.bytesAt(u, y, addr, &values, &known, runs[0..n], of.region, lead, true, moment, shift); - _ = reading(u, y, shift, moment, &values, &known, readings[0..n]); + _ = readingIn(u, y, shift, moment, &values, &known, readings[0..n], room); } } @@ -604,9 +693,16 @@ fn fieldRow(u: ui.Ui, now: cursors.Now, y: f32, addr: u64, moment: Recording.Mom /// `loose`, as nothing. Cut where the panel ends, with `…`. Returns where /// it ends. pub fn reading(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field) f32 { + return readingIn(u, y, shift, moment, values, known, fields, full_room); +} + +/// The panel's width less its side: where a reading ends with no pin at its row's end. +const full_room = theme.layout.state.w - theme.metric.context.side; + +/// `reading`, ending at `room` (a pin at the row's end takes the rest). +pub fn readingIn(u: ui.Ui, y: f32, shift: f32, moment: Recording.Moment, values: *const [16]u8, known: *const [16]bool, fields: []const Field, room: f32) f32 { const size = theme.size.mono.context; const base = rows.baseline(y); - const room = theme.layout.state.w - theme.metric.context.side; var x: f32 = b.reading + shift; for (fields) |fl| { const first: usize = @intCast(fl.at); diff --git a/anim/src/map.zig b/anim/src/map.zig index 255ea2d..c870d60 100644 --- a/anim/src/map.zig +++ b/anim/src/map.zig @@ -383,6 +383,7 @@ pub const Map = struct { const context = @import("context.zig"); context.zoomed = @splat(null); const t = placed.value(m.t); + context.thread_shows = std.math.clamp((t - diving.land) / 12, 0, 1); if (t >= diving.land) return; const fixed = @import("words.zig").fixed(f, placed, 0); const at = m.falling(f, placed, t); @@ -671,6 +672,10 @@ pub fn minimap(m: *const Map, f: *sk.Frame, at: anim.Placed) void { placed.scale = fixed.at.scale * theme.minimap.scale; const values = f.scratch.dupe(f32, at.values) catch return; placed.values = values; + // Its drawings outline the windows in their images' pixels: where the + // falling map has them (a dive's panels set off from there) is kept. + const falling_px = window_px; + defer window_px = falling_px; const n = theme.time.minimap_fade; var weights: [n]f32 = @splat(0); var made: usize = 0; diff --git a/anim/src/root.zig b/anim/src/root.zig index 7e4206a..60ae6dc 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -253,6 +253,13 @@ pub const Context = struct { return add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet }); } + /// The ties, and a link the scene plays on a beat of its own (`Beat.play`): + /// register `name` framed as read, then linked to what it points at, held `hold`. + pub fn tiesWith(c: Context, s: *anim.Frame, name: []const u8, hold: f32) struct { anim.Obj, *const tying.Beat } { + const beat = s.new(tying.Beat{ .cursor = c.cursor, .name = name, .hold = hold, .t = s.value(-1) }); + return .{ add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet, .beat = beat }), beat }; + } + /// A scene's opening with a lens drawn from bytes (`nodes`, `array`): /// as `establish`, and from half a second in the drawing's /// `elements` come in, each rising 8 units, 2 f apart in address diff --git a/anim/src/rows.zig b/anim/src/rows.zig index a125b05..95400be 100644 --- a/anim/src/rows.zig +++ b/anim/src/rows.zig @@ -56,6 +56,9 @@ pub const Marks = struct { extend: ?f32 = null, /// The first hop's `lead` (a column of addresses). lead: usize = 0, + /// How much the hops after the first show: they fade out as the memory + /// they read is about to change (`Now.following`). + hops: f32 = 1, }; /// `chain` of a memory access narrower than a word: its address, then what @@ -119,7 +122,8 @@ pub fn chain(u: ui.Ui, x: f32, y: f32, moment: Recording.Moment, value: u64, roo const shown = ui.Value.of(link.value, pointer); const w = shown.width(); // The hops after a struck first one are followed again, one at a time. - const v = if (i > 0 and marks.extend != null) u.faded(std.math.clamp((marks.extend.? - @as(f32, @floatFromInt(i - 1)) * theme.time.unroll) / (6.0 / 60.0), 0, 1)) else u; + const followed: f32 = if (marks.extend) |e| std.math.clamp((e - @as(f32, @floatFromInt(i -| 1)) * theme.time.unroll) / (6.0 / 60.0), 0, 1) else 1; + const v = if (i > 0) u.faded(followed * marks.hops) else u; if (i > 0) { const named: f32 = if (link.region == .code and link.text.len > 0 and !link.string) 10 + @as(f32, @floatFromInt(link.text.len)) * adv else 0; // Room for it, and for saying there is more. diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig index ca98920..b568612 100644 --- a/anim/src/syscalls.zig +++ b/anim/src/syscalls.zig @@ -128,7 +128,9 @@ pub fn step(c: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { while (call < made.enter and !(if (rec.insn_branches[call]) |b| b.kind == .call else false)) call += 1; if (call >= made.enter) call = from; // 1, the instructions before the call: a cascade, the plaque onto the - // call's row 12 f after the last strike, no rest (the line stays current). + // call's row 12 f after the last strike, no rest (the line stays current): + // what it struck cools on into the crossing. + var cooling: f32 = 0; if (call > from) { var before = c.reading(from, call); const regs_before: f32 = @floatFromInt(@popCount(rec.registersChanged(from, call) & ~cursors.quiet)); @@ -139,12 +141,14 @@ pub fn step(c: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void { before.advance = last + 12.0 / 60.0; before.travel = time.step; before.total = before.advance + before.travel; + cooling = time.strike.cool - before.travel; c.step(s, call, before, before.total); } // 2, the crossing from the call row (its chart's frame 18 first); 3, the stores after. const p = if (call > from) Plan.of(made).shifted(-time.cascade) else Plan.of(made); var plan = p.step(); plan.fires = call == from; + plan.cooling = cooling; // The store after the call: 18 f after rax, and after the registers the call left (6 f apart). const regs: f32 = @floatFromInt(@popCount(rec.registersChanged(call, to) & ~cursors.quiet)); const last_register = p.struck + @min(@max(regs - 1, 0), 3) * cursors.write_apart; @@ -263,35 +267,56 @@ pub const Crossing = struct { var first: usize = 0; while (first < rec.syscalls.len and rec.syscalls[first].enter < c.cursor.first) first += 1; var newest = latest(rec, now.stops[0]); - // A crossing's own row comes in once it is back (rax struck), 12 f. + // A crossing's own row comes in once it is back (rax struck): the + // rows make room for it, a full log scrolling a row (24 f, `glide`), + // as it fades in (12 f), and the count above crossfades with them. var arrives: f32 = 1; if (newest) |n| if (inStep(now) != null and now.walking()) { const p = Plan.in(now, rec.syscalls[n]); - arrives = std.math.clamp((now.time - p.struck - 6.0 / 60.0) / theme.time.quick, 0, 1); + arrives = std.math.clamp((now.time - p.struck - 6.0 / 60.0) / theme.time.move, 0, 1); }; if (newest) |n| if (n < first) { newest = null; }; const count = if (newest) |n| n + 1 - first else 0; - const body = u.panel(box.w, box.h, "system calls", .{ .focus = c.focus, .note = if (count > room) u.print("as strace writes them \u{00b7} newest at the bottom \u{00b7} {d} more above", .{count - room}) else "as strace writes them \u{00b7} newest at the bottom" }); + const above = [2]usize{ (count -| 1) -| room, count -| room }; + const notes = [2][]const u8{ logNote(u, above[0]), logNote(u, above[1]) }; + const scroll = cursors.glide(arrives); + const renote = above[0] != above[1] and arrives < 1; + const body = u.panel(box.w, box.h, "system calls", .{ .focus = c.focus, .note = if (renote) "" else notes[1] }); + if (renote) { + u.faded(1 - scroll).tagNote(box.w, notes[0]); + u.faded(scroll).tagNote(box.w, notes[1]); + } context.clipBody(u, box); defer u.unclip(); const n = newest orelse return; const top = body.y + theme.metric.context.pad; const shown = @min(count, room); - for (0..shown) |j| { - const i = n + 1 - shown + j; - const v = if (i == n) u.faded(arrives) else u; - const y = top + @as(f32, @floatFromInt(j)) * row_h; + // A full log's oldest row shown goes up and out as the new one comes. + const scrolls = arrives < 1 and count > room; + const from = n + 1 - shown - @intFromBool(scrolls); + for (from..n + 1) |i| { + const fresh = std.math.clamp(arrives * theme.time.move / theme.time.quick - 1, 0, 1); + const v = if (i == n) u.faded(fresh) else u; + const row: f32 = @as(f32, @floatFromInt(i - from)) - if (scrolls) scroll else 0; + const y = top + row * row_h; logRow(v, rec, rec.syscalls[i], y, box.w - theme.metric.context.side); // The newest's turned corner; the one before keeps it until the new row is in. if (i == n) v.corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1); - if (i + 1 == n and arrives < 1) u.faded(1 - arrives).corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1); + if (i + 1 == n and fresh < 1) u.faded(1 - fresh).corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1); } } + fn logNote(u: ui.Ui, above: usize) []const u8 { + return if (above > 0) u.print("as strace writes them \u{00b7} newest at the bottom \u{00b7} {d} more above", .{above}) else "as strace writes them \u{00b7} newest at the bottom"; + } + /// A call as strace writes it, its arguments by name: `read fd 3 - /// "note" buf 7fffffffecd0 count 32 = 15`, cut at `room` with `…`. + /// "note" buf 7fffffffecd0 count 32 = 15`, a path by its string (as the + /// kernel took it, where the stop did not read it). Out of room the + /// faint names go first, then the arguments from the right (`…`); what + /// it returned stays. fn logRow(u: ui.Ui, rec: *const Recording, made: Recording.Syscall, y: f32, room: f32) void { const base = theme.baseline(y, row_h, size); const adv = ui.advance(size); @@ -301,16 +326,18 @@ pub const Crossing = struct { x += u.width(.mono_bold, size, name) + adv; const names = zt.syscalls.names(made.nr); const n = @min(zt.syscalls.signature(made.nr).len, 6); - const Part = struct { text: []const u8, ink: u24 }; + const Part = struct { text: []const u8, ink: u24, name: bool = false }; var parts: [32]Part = undefined; var np: usize = 0; for (0..n) |j| { const what = if (j < names.len) names[j] else ""; if (what.len > 0) { - parts[np] = .{ .text = what, .ink = theme.color.text.dim }; + parts[np] = .{ .text = what, .ink = theme.color.text.dim, .name = true }; np += 1; } - parts[np] = .{ .text = @import("disasm.zig").argument(u, rec, made.enter, what, made.args[j]), .ink = theme.color.text.primary }; + var said = @import("disasm.zig").argument(u, rec, made.enter, what, made.args[j]); + if (std.mem.eql(u8, what, "path") and said[0] != '"' and made.text.len > 0) said = u.print("\"{s}\"", .{made.text[0 .. std.mem.indexOfScalar(u8, made.text, 0) orelse made.text.len]}); + parts[np] = .{ .text = said, .ink = theme.color.text.primary }; np += 1; if (std.mem.endsWith(u8, what, "fd")) { const on = rec.openOn(u.f.scratch, made.args[j], made.enter); @@ -320,19 +347,25 @@ pub const Crossing = struct { } } } - parts[np] = .{ .text = "=", .ink = theme.color.text.faint }; - np += 1; - parts[np] = .{ .text = if (made.exit != null) result(u, made) else "?", .ink = theme.color.text.primary }; - np += 1; + const answer = u.print("= {s}", .{if (made.exit != null) result(u, made) else "?"}); + const answer_w = u.width(.mono, size, answer); + var total: f32 = 0; + for (parts[0..np]) |part| total += u.width(.mono, size, part.text) + adv; + // The faint names first, where all of it does not fit. + const named = x + total + answer_w <= room; for (parts[0..np]) |part| { + if (part.name and !named) continue; const w = u.width(.mono, size, part.text); - if (x + w > room) { + if (x + w + adv + answer_w > room) { u.text(.mono, size, x, base, "\u{2026}", theme.color.text.faint); - return; + x += 2 * adv; + break; } u.text(.mono, size, x, base, part.text, part.ink); x += w + adv; } + u.text(.mono, size, x, base, "=", theme.color.text.faint); + u.text(.mono, size, x + 2 * adv, base, answer[2..], theme.color.text.primary); } /// Its view: the bytes the call crossing in this step is given or @@ -390,6 +423,7 @@ pub const Crossing = struct { .region = context.ink(context.regionOf(now.moment(), sp.addr)), .given = .{ .addr = sp.addr, .bytes = text, .shows = 1, .since = if (fills(given) != null) tm - p.fills else null }, .read = if (bufferRead(given) != null) now.held(p.work) else 0, + .pins = true, }); v.veil(now); } diff --git a/anim/src/ties.zig b/anim/src/ties.zig index e25c34b..58ada36 100644 --- a/anim/src/ties.zig +++ b/anim/src/ties.zig @@ -46,8 +46,10 @@ pub const Place = union(enum) { node_pin: u64, /// A part of a node (its value, its pointer half), by the address of the field it is drawn from. node_part: u64, - /// A run of bytes in the lens's dump, by its address. + /// A run of bytes in the lens's dump, by its address; a view's row, by + /// its first byte's: where a link to what a register points at lands. dump_run: u64, + dump_pin: u64, /// The source's current line; the disassembly's pc row; each run of /// the current line's instructions in the disassembly. source, @@ -69,6 +71,7 @@ pub const Place = union(enum) { .source => 10 << 56, .pc => 11 << 56, .run => |k| 12 << 56 | @as(u64, k), + .dump_pin => |a| 13 << 56 | (a & low), }; } }; @@ -178,6 +181,8 @@ pub const Ties = struct { threaded: bool = true, /// No links: the registers are not marked (`Registers.quiet`). quiet: bool = false, + /// A link the scene plays on a beat of its own (`Context.tiesWith`). + beat: ?*const Beat = null, pub fn draw(g: *const Ties, f: *sk.Frame, at: anim.Placed) void { defer said = 0; @@ -192,7 +197,8 @@ pub const Ties = struct { raw.at.xf = .identity; const k = at.scale; const split = g.stage.now(at); - if (g.threaded) thread(raw, at, k); + if (g.threaded) thread(raw.faded(@import("context.zig").thread_shows), at, k); + if (g.beat) |b| named(raw, at, now, k, split, b); if (!now.walking()) return; if (!g.quiet) g.link(raw, at, now, k, split); g.projection(raw, at, now, k, split); @@ -217,84 +223,119 @@ pub const Ties = struct { } /// The step's link: the first register it struck that now holds the - /// address of a pinned thing (a stack slot, a node). rip and rsp are - /// where execution and the stack are, and have none. + /// address of a pinned thing (a stack slot, a node, a view's row). rip + /// and rsp are where execution and the stack are, and have none. fn link(g: *const Ties, raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split) void { const rec = g.cursor.rec; const regs = (now.moment().regs(rec.tid) catch null) orelse return; - const edge = find(.registers) orelse return; for (theme.metric.all_registers[0..16]) |name| { const i = @import("context.zig").index(name).?; if (now.registerAge(i) != 0 or std.mem.eql(u8, name, "rsp")) continue; const value = regs.named(name) orelse continue; - const from = find(.{ .register = i }) orelse continue; - const node = find(.{ .node_pin = value }); - // A word of the stack outside its window: the link ends at the - // window's edge, with a stub and how many words on it is. - var beyond: ?i64 = null; - const target = node orelse find(.{ .slot_pin = value }) orelse edge: { - const w = stack_window orelse continue; - if (value % 8 != 0 or rows.regionOf(now.moment(), value) != .stack) continue; - const words = @as(i64, @bitCast(value -% w.first)) >> 3; - if (words >= 0 and words < w.slots) continue; - if (@abs(words) > 64) continue; - beyond = if (words < 0) words else words - @as(i64, @intCast(w.slots)) + 1; - // Its nearest row's pin lane. - const y = if (words < 0) w.top else w.top + @as(f32, @floatFromInt(w.slots - 1)) * w.row; - break :edge [4]f32{ w.x, y, w.x + 10 * k, y + w.row }; - }; const since = linkSince(now, i); const l = time.link; - const drawn = cursors.standard(std.math.clamp((since - l.after) / linkTime(if (node != null) .node else .slot), 0, 1)); + const node = find(.{ .node_pin = value }) != null; + const drawn = cursors.standard(std.math.clamp((since - l.after) / linkTime(if (node) .node else .slot), 0, 1)); const back = std.math.clamp((now.time - now.plan.advance) / l.out, 0, 1); - if (drawn <= 0 or back >= 1) return; - const color = rows.ink(rows.regionOf(now.moment(), value)); - const y = (from[1] + from[3]) / 2; - // What climbs into the band takes the gutter's left lane; what - // goes down to a slot, the right. - const lane = at.xf.apply(.{ if (node != null) theme.metric.tie.link_lane else theme.metric.tie.projection_lane, 0 })[0]; - var points: [5]ui.Vec = undefined; - var n: usize = 0; - points[0] = .{ edge[0] + 2 * k, y }; - points[1] = .{ lane, y }; - if (node) |pin| { - // Up the gutter, along the lens's bottom lane, up into the pin under the node. - const bottom = at.xf.apply(.{ 0, split.band.y + split.band.h - theme.metric.lens.bottom_lane })[1]; - const cx = (pin[0] + pin[2]) / 2; - points[2] = .{ lane, bottom }; - points[3] = .{ cx, bottom }; - points[4] = .{ cx, pin[1] }; - n = 5; - } else if (beyond) |words| { - // Off the window: to its nearest row, into the pin lane, out - // to the panel's rule, where a head points on. - const mid = (target[1] + target[3]) / 2; - const rule = if (words < 0) target[1] - 6 * k else target[3] + 6 * k; - points[2] = .{ lane, mid }; - points[3] = .{ target[0] + 6 * k, mid }; - points[4] = .{ target[0] + 6 * k, rule }; - n = 5; - } else { - // Along the gutter to the slot's row, and into its pin lane. - const mid = (target[1] + target[3]) / 2; - points[2] = .{ lane, mid }; - points[3] = .{ target[0] - 2 * k, mid }; - n = 4; - } - raw.route(points[0..n], color, .{ .width = theme.stroke.tie.link * k, .head = if (beyond == null) .{ 10 * k, 10 * k } else .{ 9 * k, 12 * k }, .progress = drawn, .from = cursors.standard(back), .radius = theme.metric.tie.radius * k }); - if (beyond) |words| if (drawn >= 1) { - // How far the target is, faint, 6 past the head. - const v = raw.faded(1 - std.math.clamp((now.time - now.plan.advance) / l.out, 0, 1)); - const tip = points[4]; - v.text(.mono, theme.size.mono.context, tip[0] + 12 * k, tip[1] + (if (words < 0) @as(f32, 6) else 14) * k, v.print("{d} rows", .{@abs(words)}), theme.color.text.faint); - }; - // The pin rides the line's head: the register's name beside it. - if (drawn > 0 and drawn < 1 and beyond == null) { - const tip = along(points[0..n], drawn); - raw.text(.mono_bold, theme.size.mono.context, tip[0] + 8 * k, tip[1] - 6 * k, name, theme.color.text.primary); - } - return; + if (linkTo(raw, at, now, k, split, name, value, drawn, back)) return; + } + } + + /// A link from register `name` to what it points at (`value`): a node's + /// pin, a slot's, a view's row, or a slot past the stack's window (a + /// stub and a row count), `drawn` of the way and drawing back `back` of + /// it. False where `value` is no such place. + fn linkTo(raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split, name: []const u8, value: u64, drawn: f32, back: f32) bool { + const i = @import("context.zig").index(name) orelse return false; + const edge = find(.registers) orelse return false; + const from = find(.{ .register = i }) orelse return false; + const node = find(.{ .node_pin = value }); + // A view's row it points into: up the gutter to the row's left edge. + const row = if (node == null) find(.{ .dump_pin = value & ~@as(u64, 15) }) else null; + // A word of the stack outside its window: the link ends at the + // window's edge, with a stub and how many words on it is. + var beyond: ?i64 = null; + const target = node orelse find(.{ .slot_pin = value }) orelse row orelse edge: { + const w = stack_window orelse return false; + if (value % 8 != 0 or rows.regionOf(now.moment(), value) != .stack) return false; + const words = @as(i64, @bitCast(value -% w.first)) >> 3; + if (words >= 0 and words < w.slots) return false; + if (@abs(words) > 64) return false; + beyond = if (words < 0) words else words - @as(i64, @intCast(w.slots)) + 1; + // Its nearest row's pin lane. + const y = if (words < 0) w.top else w.top + @as(f32, @floatFromInt(w.slots - 1)) * w.row; + break :edge [4]f32{ w.x, y, w.x + 10 * k, y + w.row }; + }; + const l = time.link; + if (drawn <= 0 or back >= 1) return true; + const color = rows.ink(rows.regionOf(now.moment(), value)); + const y = (from[1] + from[3]) / 2; + // What climbs into the band takes the gutter's left lane; what + // goes down to a slot, the right. + const lane = at.xf.apply(.{ if (node != null or row != null) theme.metric.tie.link_lane else theme.metric.tie.projection_lane, 0 })[0]; + var points: [5]ui.Vec = undefined; + var n: usize = 0; + points[0] = .{ edge[0] + 2 * k, y }; + points[1] = .{ lane, y }; + if (node) |pin| { + // Up the gutter, along the lens's bottom lane, up into the pin under the node. + const bottom = at.xf.apply(.{ 0, split.band.y + split.band.h - theme.metric.lens.bottom_lane })[1]; + const cx = (pin[0] + pin[2]) / 2; + points[2] = .{ lane, bottom }; + points[3] = .{ cx, bottom }; + points[4] = .{ cx, pin[1] }; + n = 5; + } else if (beyond) |words| { + // Off the window: to its nearest row, into the pin lane, out + // to the panel's rule, where a head points on. + const mid = (target[1] + target[3]) / 2; + const rule = if (words < 0) target[1] - 6 * k else target[3] + 6 * k; + points[2] = .{ lane, mid }; + points[3] = .{ target[0] + 6 * k, mid }; + points[4] = .{ target[0] + 6 * k, rule }; + n = 5; + } else { + // Along the gutter to the row, and into its pin lane (a view's row: to its edge). + const mid = (target[1] + target[3]) / 2; + points[2] = .{ lane, mid }; + points[3] = .{ target[0] + (if (row != null) @as(f32, 2) else -2) * k, mid }; + n = 4; + } + raw.route(points[0..n], color, .{ .width = theme.stroke.tie.link * k, .head = if (beyond == null) .{ 10 * k, 10 * k } else .{ 9 * k, 12 * k }, .progress = drawn, .from = cursors.standard(back), .radius = theme.metric.tie.radius * k }); + if (beyond) |words| if (drawn >= 1) { + // How far the target is, faint, 6 past the head. + const v = raw.faded(1 - back); + const tip = points[4]; + v.text(.mono, theme.size.mono.context, tip[0] + 12 * k, tip[1] + (if (words < 0) @as(f32, 6) else 14) * k, v.print("{d} rows", .{@abs(words)}), theme.color.text.faint); + }; + // The pin rides the line's head: the register's name beside it. + if (drawn > 0 and drawn < 1 and beyond == null) { + const tip = along(points[0..n], drawn); + raw.text(.mono_bold, theme.size.mono.context, tip[0] + 8 * k, tip[1] - 6 * k, name, theme.color.text.primary); } + _ = l; + return true; + } + + /// The scene's `Beat`: its register framed as read, then its link. + fn named(raw: ui.Ui, at: anim.Placed, now: cursors.Now, k: f32, split: theme.layout.Split, b: *const Beat) void { + const t = at.value(b.t); + if (t < 0 or t >= b.total()) return; + const i = @import("context.zig").index(b.name) orelse return; + const px = find(.{ .register = i }) orelse return; + const l = time.link; + const back = std.math.clamp((t - (b.total() - l.out)) / l.out, 0, 1); + // Its value framed as read, in the panel's units. + const u: ui.Ui = .{ .f = raw.f, .at = at }; + const inv = at.xf.invert(); + const a = inv.apply(.{ px[0], px[1] }); + const c = inv.apply(.{ px[2], px[3] }); + u.read(.{ .x = a[0], .y = a[1], .w = c[0] - a[0], .h = c[1] - a[1] }, std.math.clamp(t / time.read.in, 0, 1) * (1 - back)); + const rec = b.cursor.rec; + const regs = (now.moment().regs(rec.tid) catch null) orelse return; + const value = regs.named(b.name) orelse return; + const drawn = cursors.standard(std.math.clamp((t - l.after) / l.in_far, 0, 1)); + _ = linkTo(raw, at, now, k, split, b.name, value, drawn, back); } /// The step's projection: the first run of bytes it read or wrote in @@ -361,6 +402,31 @@ pub const Ties = struct { } }; +/// A link the narration plays on a beat the caption names, not a step's: +/// register `name` framed as read (6 f), then its link to what it points at +/// (6 f after, 36 f, `standard`, the name riding its head), held `hold`, +/// and drawn back with the frame (18 f). +pub const Beat = struct { + cursor: cursors.Cursor, + name: []const u8, + hold: f32, + /// Seconds into it; negative: none. + t: anim.Value, + + pub fn total(b: *const Beat) f32 { + return time.link.after + time.link.in_far + b.hold + time.link.out; + } + + /// Plays it from here; the scene's cursor stays where it was. + pub fn play(b: *const Beat, s: *anim.Frame) void { + const start = s.cursor; + s.play(.{b.t.to(0)}, .{ .seconds = 0 }); + s.play(.{b.t.to(b.total())}, .{ .seconds = b.total(), .ease = anim.ease.linear }); + s.play(.{b.t.to(-1)}, .{ .seconds = 0 }); + s.cursor = start; + } +}; + /// The point `p` of the way along the straight path through `points`. fn along(points: []const ui.Vec, p: f32) ui.Vec { var total: f32 = 0; diff --git a/anim/src/ui.zig b/anim/src/ui.zig index d770e05..bcefff3 100644 --- a/anim/src/ui.zig +++ b/anim/src/ui.zig @@ -487,6 +487,21 @@ pub const Ui = struct { sk.draw.polygon(u.f, &.{ .{ hx + p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = rgb(ink) })); } + /// `pin` `row` at a dump row's right end (a view has no lane before its + /// addresses): the head pointing left at the row, then the names, + /// ending at `right`. Returns where it begins. + pub fn pinEnd(u: Ui, right: f32, y: f32, names: []const []const u8, ink: anytype) f32 { + const size = theme.size.mono.context; + const p = theme.metric.pin; + const shown = joined(u, names); + const x = right - u.width(.mono, size, shown); + u.text(.mono_bold, size, x, theme.baseline(y, theme.metric.context.row, size), shown, theme.color.text.primary); + const hx = x - p.row_gap; + const mid = y + theme.metric.context.row / 2; + sk.draw.polygon(u.f, &.{ .{ hx - p.row_head[0], mid }, .{ hx, mid - p.row_head[1] / 2 }, .{ hx, mid + p.row_head[1] / 2 } }, u.at.pen(.{ .fill = rgb(ink) })); + return hx - p.row_head[0]; + } + /// `pin` `under`: a stub 3 wide rising `size` + 10 to a node's bottom /// edge at (`cx`, `y`), a head 10 by 10 on it, the first name left of /// the stub and the others right, bold, primary. diff --git a/anim/src/words.zig b/anim/src/words.zig index 4d221f4..f66f6d2 100644 --- a/anim/src/words.zig +++ b/anim/src/words.zig @@ -162,9 +162,10 @@ pub const Veil = struct { /// it means: the same in every picture. pub const Legend = struct { box: Rect, - entries: []const Entry = &.{ .current, .written, .changed, .read, .link, .allocated, .freed, .unknown, .kernel }, + /// The marks the scenes use. + entries: []const Entry = &.{ .current, .written, .changed, .read, .waiting, .unknown, .link, .pin, .arc, .loupe, .freed, .kernel }, - pub const Entry = enum { current, written, changed, read, link, allocated, freed, unknown, kernel }; + pub const Entry = enum { current, written, changed, read, link, pin, arc, loupe, waiting, freed, unknown, kernel }; pub fn draw(l: *const Legend, f: *sk.Frame, at: anim.Placed) void { const u: ui.Ui = .{ .f = f, .at = at }; @@ -182,7 +183,10 @@ pub const Legend = struct { .changed => .{ "changed", "a moment ago" }, .read => .{ "read", "by this step" }, .link => .{ "link", "now points at that" }, - .allocated => .{ "allocated", "handed out" }, + .pin => .{ "pin", "who points here" }, + .arc => .{ "arc", "a pointer in its panel" }, + .loupe => .{ "loupe", "where it points" }, + .waiting => .{ "waiting", "for the call it made" }, .freed => .{ "freed", "handed back" }, .unknown => .{ "not seen", "never observed" }, .kernel => .{ "kernel", "the other side" }, @@ -211,9 +215,22 @@ pub const Legend = struct { u.label(.mono, size, cell, .center, digits, t.primary); }, .link => u.route(&.{ .{ r.x, r.y + 23 }, .{ r.x + r.w, r.y + 23 } }, theme.color.region.heap, .{ .width = theme.stroke.tie.link, .head = .{ 10, 10 } }), - .allocated => { - u.fill(r, theme.mark(.allocated).ember); - u.frame(r, theme.mark(.allocated).solid, theme.stroke.line); + .pin => u.pinRow(r.x, r.y + 11, &.{"rsp"}, theme.color.region.stack), + .arc => { + const k = theme.metric.arc; + u.route(&.{ .{ r.x + r.w, r.y + 8 }, .{ r.x + 20, r.y + 8 }, .{ r.x + 20, r.y + 38 }, .{ r.x + r.w, r.y + 38 } }, theme.color.region.heap, .{ .width = k.width, .head = k.head, .radius = k.radius }); + }, + .loupe => { + const k = theme.metric.loupe.shadow[0]; + u.fill(.{ .x = r.x + k[0] / 2, .y = r.y + k[1] / 2, .w = r.w - k[0] / 2, .h = r.h - k[1] / 2 }, theme.color.shade); + const lifted: Rect = .{ .x = r.x, .y = r.y, .w = r.w - k[0] / 2, .h = r.h - k[1] / 2 }; + u.fill(lifted, theme.color.lift); + u.fill(.{ .x = r.x, .y = r.y, .w = lifted.w, .h = 10 }, theme.color.lift_tag); + u.frame(lifted, t.dim, theme.stroke.rule); + }, + .waiting => { + u.frame(.{ .x = r.x + 1, .y = r.y + 1, .w = r.w - 2, .h = r.h - 2 }, t.primary, theme.stroke.rule); + u.label(.mono, size, r, .center, "call", t.primary); }, .freed => u.dashedFrame(r, theme.mark(.freed).solid, theme.stroke.line), .unknown => { |
