summaryrefslogtreecommitdiff
path: root/anim/src/graph.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 09:28:38 -0300
committerGabriel Schneider <[email protected]>2026-11-13 09:28:38 -0300
commit5c0230ea5a77f85de77ad4354788cd6c27aa1ef6 (patch)
treee01a903bdee092965b86e118dfaab85c3bd60004 /anim/src/graph.zig
parent5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (diff)
downloadcomputeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.tar.gz
computeranim-5c0230ea5a77f85de77ad4354788cd6c27aa1ef6.zip
debugger: follow natural V8 deoptimization with adaptive live views
Diffstat (limited to 'anim/src/graph.zig')
-rw-r--r--anim/src/graph.zig41
1 files changed, 40 insertions, 1 deletions
diff --git a/anim/src/graph.zig b/anim/src/graph.zig
index 9eb6f2d..03d8fc8 100644
--- a/anim/src/graph.zig
+++ b/anim/src/graph.zig
@@ -109,7 +109,7 @@ pub const Edge = struct {
/// Its length along its way.
pub fn length(e: *const Edge) f32 {
var total: f32 = 0;
- for (e.path()[0 .. e.n -| 1], e.path()[@min(1, e.n)..]) |a, b| total += dist(a, b);
+ for (e.path()[0..e.n -| 1], e.path()[@min(1, e.n)..]) |a, b| total += dist(a, b);
return total;
}
@@ -2007,6 +2007,45 @@ fn drawMark(u: ui.Ui, v: Instant) void {
/// its size: over the program column the function's graph in the form
/// the scene names (`rings`; `layers` where it has no loop), centred in
/// its pane, a block a pill. Its rows are the disassembly under the source.
+/// Bounded live-stop graph: blocks and observations only, never inferred execution counts.
+pub fn live(u: ui.Ui, m: zt.store.Moment, pc: u64, observed: [3]u64, opacity: f32) f32 {
+ const arena = u.f.scratch;
+ const probe = zt.telescope.blocks(m, pc, &.{}) orelse {
+ u.text(.sans, 20, 20, 38, "Control-flow blocks were not captured here", t.dim);
+ return 64;
+ };
+ const raw = arena.alloc(zt.telescope.Block, @min(probe.count, 4096)) catch return 0;
+ const found = zt.telescope.blocks(m, pc, raw) orelse return 0;
+ const nodes = arena.alloc(Node, found.blocks.len) catch return 0;
+ const spans = arena.alloc(Span, nodes.len) catch return 0;
+ for (found.blocks, nodes, spans, 0..) |b, *n, *span, k| {
+ n.* = .{ .start = b.start, .len = b.len, .end = b.end, .w = 270, .h = 64 };
+ span.* = .{ .start = b.start, .len = b.len, .node = @intCast(k) };
+ }
+ var edges: std.ArrayList(Edge) = .empty;
+ for (found.blocks, 0..) |b, k| {
+ if (b.to) |to| if (blockAt(nodes, to)) |at| edges.append(arena, .{ .from = @intCast(k), .to = at, .kind = if (b.end == .branch) .taken else .jump }) catch return 0;
+ if (b.falls) |to| if (blockAt(nodes, to)) |at| edges.append(arena, .{ .from = @intCast(k), .to = at, .kind = .fall }) catch return 0;
+ }
+ var g: Graph = .{ .start = found.start, .len = found.len, .nodes = nodes, .spans = spans, .edges = edges.items, .here = blockAt(nodes, pc), .text = found.text, .exact = false };
+ place(arena, &g, .layers) catch return 0;
+ const v = u.moved(16, 16);
+ var path: [most]ui.Vec = undefined;
+ for (g.edges) |edge| v.route(vecs(&path, edge.path()), if (edge.kind == .fall) t.faint else theme.color.rule, .{ .width = 1.5, .head = gm.head, .radius = 0 });
+ for (g.nodes) |node| {
+ const current = node.contains(pc);
+ const seen = for (observed) |addr| {
+ if (node.contains(addr)) break true;
+ } else false;
+ const ink = if (current) theme.mark(.current).solid else t.dim;
+ const n = v.faded(if (current or seen) 1 else @max(0.15, opacity));
+ pill(n, .{ .x = node.x, .y = node.y, .w = node.w, .h = node.h }, ui.rgb(theme.color.raised), ui.rgb(ink), if (current) 2 else 1, false);
+ _ = n.address(node.x + 16, node.y + 26, node.start, .{});
+ n.text(.mono, 16, node.x + 16, node.y + 49, n.print("{s} ยท {d} bytes", .{ @tagName(node.end), node.len }), ink);
+ }
+ return g.h + 32;
+}
+
pub const Blocks = struct {
cursor: cursors.Cursor,
stage: *const Stage,