veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

profile/flamegraph

lib/profile/flamegraph.vk

lib/profile/flamegraph.vk Pure-Veko folded-stack profiler model and Light-Mode interactive SVG flamegraph generator. Zero capabilities required; consumes folded call-stack samples (fn_a;fn_b;leaf weight_ns) and emits strict-XML, Light-Mode interactive SVG flamegraphs with click-to-zoom, hover stats, and live frame search highlighting.

signature
StackSample = struct { stack block[str], weight i64 }

One folded call-stack sample (stack ordered root -> leaf, weight in nanoseconds or sample ticks).

FnStat struct
signature
FnStat = struct { name str, calls i64, self_ns i64, incl_ns i64 }

Per-function hotspot summary row.

signature
format-ns = fn [ns i64] str

Formats nanoseconds into a compact human-readable duration ('14.2 ms', '320 us', '850 ns').

signature
parse-folded = fn [text str] block[StackSample]

Parses standard Brendan Gregg folded-stack lines ('main;parse;lex 4200\n...') into block[StackSample].

Executable Example
veko
use [fg = profile/flamegraph]
samples = fg/parse-folded 'main;parse;tokenize 400\nmain;emit 600\n'
svg = fg/render-svg 'Compiler Profile' samples
if (len samples) != 2 or not (str/contains? svg '<svg') [ err 'flamegraph failed' ] else [ .ok ]
signature
format-folded = fn [samples block[StackSample]] str

Serializes samples into canonical folded-stack text ('a;b;c 123\n').

signature
render-svg = fn [title str, samples block[StackSample], /subtitle sub str, /width svg_w i64] str

Renders a self-contained, Light-Mode interactive SVG flamegraph (click to zoom, hover for inclusive/self stats, live search bar).