Builtin Library
README.md
Flamegraph widget
Reusable icicle-flamegraph widget over Z.canvas. Engine-agnostic —
consumes anything shaped like { stacks = { { stack, self_us }, ... } },
which is exactly what luau_profile.snapshot() returns. Drop into any
tab that has folded-stack data; the Rust side never sees this module,
the engine just paints whatever rect / text canvas commands come out.
API
local Flame = require("@builtin::modules.ui.flamegraph")
local view = Flame.build({
snapshot = luau_profile.snapshot(),
width = 720,
height = 280,
search = "physics", -- optional: dim non-matching frames
onClick = "my-tab/flame-click", -- optional: forwarded to canvas event
})
Returns a single Z.canvas node ready to mount under any parent.
Frame format
The stack string per StackEntry is ;-separated frames; each frame
is short_src,name,linedefined,currentline (the wire format emitted
by the engine's sampler), innermost frame first. currentline is the
line executing when the sampler caught the stack, which splits long
functions into per-line hot spots. Native work a Luau call reached
appears as a [C],<binding>,, frame under the Luau that called it, and
time with no Luau running as the single frame [engine],native,,.
Layout
Top-down icicle. Row 0 = whole sampled time. Each row below = its
callees, widths proportional to their share of the parent's total.
Matches Brendan Gregg's flamegraph convention and tools/perfgraph.py.
Colour
Stable hash of the source-file basename, mapped into a warm palette. Two frames from the same file always get the same colour, so visual scanning across rows lines up.
Other consumers
Anywhere folded-stack data shows up. Network timings, GPU passes, arbitrary nested timing trees — they all benefit from the same visualisation. The widget knows nothing about the Luau profiler specifically.