diff options
Diffstat (limited to 'anim/src/hexdump.zig')
| -rw-r--r-- | anim/src/hexdump.zig | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/anim/src/hexdump.zig b/anim/src/hexdump.zig index fba212d..f1087ab 100644 --- a/anim/src/hexdump.zig +++ b/anim/src/hexdump.zig @@ -147,9 +147,19 @@ pub const View = struct { /// The dump: `count` rows from `first`, at `x` in `u` (the view's /// panel), the rows from `y`. The rows of what the drawing draws have -/// quiet brackets. +/// quiet brackets; a pointer to another of its rows, an `arc` (full ink +/// 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 }); +} + +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 { const v = u.moved(x, 0); + var arcs: rows.Arcs = .{}; + var at_rows: [64]RowAt = undefined; + for (at_rows[0..@min(count, at_rows.len)], 0..) |*r, i| r.* = .{ .addr = first + 16 * i, .y = y + @as(f32, @floatFromInt(i)) * m.row }; + const shown_rows = at_rows[0..@min(count, at_rows.len)]; const moment = now.shown(.memory); const lead = ui.shared(&.{ first, first + 16 * @as(u64, count -| 1) }); // Room for the addresses, once for the dump: by its widest. @@ -204,7 +214,9 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize n += 1; at += run.len; } + @import("map.zig").row(.view, addr, v, .{ .x = 0, .y = ry, .w = theme.layout.state.w, .h = m.row }); rows.bytesAt(v, ry, addr, &values, &known, runs[0..n], of.region, lead, holds_drawn, moment, shift); + 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); const end = reading(v, ry, shift, moment, &values, &known, readings[0..n]); // The size word of the chunk after: malloc's, a note after the reading. const last = runs[n - 1]; @@ -213,6 +225,64 @@ pub fn draw(u: ui.Ui, now: cursors.Now, x: f32, y: f32, first: u64, count: usize v.text(.sans, theme.size.sans.micro, end, rows.baseline(ry) - 1, v.print("malloc's: a chunk of {d}", .{size}), t.faint); } } + arcs.draw(v, theme.metric.arc.lanes.len); +} + +/// A row of a panel: its first byte's address and its top. +pub const RowAt = struct { addr: u64, y: f32 }; + +/// The `arc`s of the pointer at `field` (a word, on the row at `from`) +/// among `shown` (rows of 16 bytes, or of 8 on the stack): to the row its +/// target is in, as the step has it. Rewritten: the old arc goes dashed +/// with the arm, fades from 6 f after the strike as the new one draws at +/// full ink, and quiets with the cool. Read: full ink while the read is +/// framed. A target in the same region past the rows shown: a stub to the +/// panel's rule (`rule`: its top and bottom), only in the step that +/// touches it. `loud`: full ink always (a loupe's, opened to show them). +pub fn pointerArcs(arcs: *rows.Arcs, now: cursors.Now, field: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, loud: bool) void { + const a = time_arc; + const new = (Recording.word(now.moment(), field, 8) catch null) orelse return; + const old = (Recording.word(now.before(), field, 8) catch null) orelse new; + const written = now.writeAge(field, 8) == 0 and old != new; + const read = now.wasRead(field, 8) and !written; + const hot = written or read; + const full: f32 = if (loud) 1 else if (read) now.reading(.memory, 0) else 0; + if (written and now.walking()) { + const since = now.since(.memory, now.writeDelay(field, 8)); + const heat = now.written(field, 8, .memory, 0); + const armed = since >= -theme.time.strike.arm; + aim(arcs, now, field, old, from, shown, size, rule, .{ .full = full, .dashed = armed, .shows = 1 - std.math.clamp((since - a.after) / a.fade, 0, 1), .hot = true }); + if (since >= a.after) aim(arcs, now, field, new, from, shown, size, rule, .{ .full = if (loud) 1 else heat.solid, .drawn = cursors.standard(std.math.clamp((since - a.after) / a.draw, 0, 1)), .hot = true }); + return; + } + aim(arcs, now, field, if (written and !now.landed(.memory, 0)) old else new, from, shown, size, rule, .{ .full = full, .hot = hot }); +} + +const time_arc = theme.time.arc; + +/// One arc from the row at `from` to the row of `shown` that holds +/// `target`; a stub toward the rule for one in the region past them, only +/// for the step's (`state.hot`). +fn aim(arcs: *rows.Arcs, now: cursors.Now, field: u64, target: u64, from: f32, shown: []const RowAt, size: u64, rule: [2]f32, state: rows.Arcs.Arc) void { + if (target == 0 or shown.len < 2) return; + const moment = now.moment(); + var arc = state; + arc.from = from; + arc.ink = rows.ink(rows.regionOf(moment, target)); + for (shown) |r| if (target >= r.addr and target < r.addr + size) { + if (r.y == from) return; + arc.to = r.y; + // A loupe open on both rows carries this arc: the dump withholds it. + if (size == 16 and arc.full < 1) for (@import("loupe.zig").holding) |h| if (h) |o| { + if (field >= o.lo and field < o.hi and target >= o.lo and target < o.hi) arc.shows *= 1 - o.shows; + }; + return arcs.add(arc); + }; + // Past the rows: a stub, in the step that touches it, when it is the same region's. + if (!state.hot or rows.regionOf(moment, target) != rows.regionOf(moment, field) or rows.regionOf(moment, target) == .none) return; + arc.stub = true; + arc.to = if (target < shown[0].addr) rule[0] else rule[1]; + arcs.add(arc); } /// Whether an allocation the recording has begins just after the word at @@ -294,6 +364,7 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { }.row; var ry = y; var last: ?u64 = null; + var at_rows: std.ArrayList(RowAt) = .empty; for (shown) |r| { // A stretch left out: one row, three dots and a count. const gap = if (last) |l| r - l - 1 else r; @@ -303,9 +374,17 @@ pub fn fielded(v: View, now: cursors.Now, y: f32, of: Fields) void { } last = r; fieldRow(u, now, ry, of.base + 16 * r, moment, of, lead, shift); + at_rows.append(u.f.scratch, .{ .addr = of.base + 16 * r, .y = ry }) catch {}; ry += m.row; } if (shown[shown.len - 1] < total - 1) more(u, ry, total - 1 - shown[shown.len - 1]); + // Its pointers to its own rows: arcs. + var arcs: rows.Arcs = .{}; + if (at_rows.items.len > 1) for (of.fields) |field| if (field.reads == .pointer and field.len == 8) { + const addr = of.base + field.at; + for (at_rows.items) |r| if (addr >= r.addr and addr < r.addr + 16) pointerArcs(&arcs, now, addr, r.y, at_rows.items, 16, .{ y - m.pad, ry + m.pad }, false); + }; + arcs.draw(u, theme.metric.arc.lanes.len); } /// Which of `rs` (rows of fields, the region's last row `last`) a window |
