{width > 0 &&
layout.rects.map((r) => {
const node = profile.nodes[r.node]!;
@@ -120,17 +150,24 @@ function FlameGraph({ profile, query }: { profile: Profile; query: string }) {
return (
setFocus(r.node)}
+ onClick={() => {
+ setCurrent(r.node);
+ setFocus(r.node);
+ }}
onDoubleClick={() => openFrame(profile, node.frame)}
>
{w > 28 &&
{label}}
diff --git a/src/features/profiler/model.ts b/src/features/profiler/model.ts
index 7533ca8bf..6868ba3d1 100644
--- a/src/features/profiler/model.ts
+++ b/src/features/profiler/model.ts
@@ -110,6 +110,34 @@ export function flameLayout(profile: Profile, focus = 0, minWidth = 0.002): { re
return { rects, depth: maxDepth + 1 };
}
+/**
+ * Keyboard moves in the flame graph from the frame `node`: `deeper` to its widest callee,
+ * `shallower` to its caller, `previous` / `next` to the neighbouring frame on its row.
+ */
+export function flameStep(
+ rects: readonly FlameRect[],
+ node: number,
+ move: "deeper" | "shallower" | "previous" | "next",
+): number {
+ const at = rects.find((r) => r.node === node);
+ if (!at) return rects[0]?.node ?? node;
+ switch (move) {
+ case "deeper": {
+ const inside = rects.filter((r) => r.depth === at.depth + 1 && r.x >= at.x && r.x < at.x + at.width);
+ return inside.reduce
((a, r) => (!a || r.width > a.width ? r : a), undefined)?.node ?? node;
+ }
+ case "shallower":
+ // A callee starts inside its caller's span.
+ return rects.find((r) => r.depth === at.depth - 1 && r.x <= at.x && at.x < r.x + r.width)?.node ?? node;
+ case "previous":
+ case "next": {
+ const row = rects.filter((r) => r.depth === at.depth).sort((a, b) => a.x - b.x);
+ const i = row.indexOf(at) + (move === "next" ? 1 : -1);
+ return row[i]?.node ?? node;
+ }
+ }
+}
+
const parentCache = new WeakMap();
/** Parent node of every node (-1 for the root). */
diff --git a/src/features/profiler/profiler.test.ts b/src/features/profiler/profiler.test.ts
index d587d21d3..63f099f61 100644
--- a/src/features/profiler/profiler.test.ts
+++ b/src/features/profiler/profiler.test.ts
@@ -4,6 +4,7 @@ import {
allocationProfilerSupports,
colorSlot,
flameLayout,
+ flameStep,
formatWeight,
frameLocation,
matchingFrames,
@@ -108,3 +109,22 @@ describe("profiler model", () => {
expect(colorSlot("main")).toBeGreaterThanOrEqual(1);
});
});
+
+describe("flameStep", () => {
+ // root (0) → a (1, 60%) and b (2, 40%); a → c (3)
+ const rects = [
+ { node: 0, depth: 0, x: 0, width: 1 },
+ { node: 1, depth: 1, x: 0, width: 0.6 },
+ { node: 2, depth: 1, x: 0.6, width: 0.4 },
+ { node: 3, depth: 2, x: 0, width: 0.5 },
+ ];
+ it("goes to the widest callee, the caller and the neighbours on a row", () => {
+ expect(flameStep(rects, 0, "deeper")).toBe(1);
+ expect(flameStep(rects, 1, "next")).toBe(2);
+ expect(flameStep(rects, 2, "next")).toBe(2);
+ expect(flameStep(rects, 2, "previous")).toBe(1);
+ expect(flameStep(rects, 2, "deeper")).toBe(2);
+ expect(flameStep(rects, 3, "shallower")).toBe(1);
+ expect(flameStep(rects, 2, "shallower")).toBe(0);
+ });
+});