moon-pprof

    Pure-MoonBit Google pprof (profile.proto) parser, differential profiler, CI regression gate, and interactive flamegraph renderer

    pprof
    profiler
    flamegraph
    performance
    protobuf
    cli
    Download zip
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    26 minutes ago
    Downloads
    5

    #moon-pprof

    纯 MoonBit 实现的 Google pprof(profile.proto)二进制性能剖析引擎、A/B 差异火焰图(Differential Flamegraph)渲染器与 CI 性能回归门禁工具。

    项目以全目标纯 MoonBit 核心库(Sam-Hui-dot/moon-pprof,支持 wasm / wasm-gc / js / native)与命令行工具(cmd/main)双形态交付。不依赖外部 go tool pprof 运行时,即可直接解析 .pb 与 gzip 压缩的 .pb.gz 剖析文件,产出 top 热点统计、folded 调用栈、红蓝差异火焰图 SVG、离线可搜索/缩放单文件 HTML 报告以及 GitHub Actions 性能门禁。

    #核心能力

    • 原生 profile.proto 编解码与 Gzip 自动解包:零外部 C 绑定实现 Protobuf Wire Format(varint / length-delimited / packed repeated / 未知字段安全跳过),通过 moonbit-community/flate/gzip 自动解包 .pb.gz,并支持 encode_profile 编码与全链路 round-trip 校验。
    • 与 go tool pprof 对齐的聚合语义:正确按 leaf-first 顺序展开内联帧(Location.lines),在计算 cum 时对递归栈帧去重避免重复计入,支持多指标(cpu / samples / alloc_space 等)与 default_sample_type 解析。
    • 多文件合并(merge):支持将多台机器/多时间窗口采集的 .pb.gz 按字符串表重映射、函数/位置去重、样本累加合并为规范 .pb.gz,与官方 go tool pprof -proto 0 误差一致。
    • 标签切片与噪音过滤:支持按 Sample.label(如 HTTP 路由/租户/Goroutine 标签)分组汇总(labels)与定向过滤,并提供 --focus / --ignore / --hide 规则以屏蔽 runtime.* 等底层噪音栈帧。
    • A/B 性能差分与 CI 回归门禁:对比基线与候选两份 profile,支持绝对差分与占比归一化(--normalize),自动标记 regressed / improved / added / removed / unchanged,按总回归比例与单函数阈值返回退出码(0 通过、1 回归拦截、2 输入或解析错误)。
    • 交互式火焰图与差异火焰图(SVG / 离线 HTML):
      • 单文件火焰图:暖色系前缀合并树,悬停显示完整函数名、cum、flat 与占比。
      • 差异火焰图(Differential Flamegraph):遵循 Brendan Gregg 红蓝配色规范——红色越深表示性能退化越重、蓝色越深表示优化下降越多、浅灰表示基本持平。
      • 单文件离线 HTML 报告:零外部 CDN,内置关键词高亮搜索、点击任意栈帧缩放(Zoom / Reset)与 Top 热点/回归表格。

    #快速使用

    #1. 作为 MoonBit 核心库导入(支持 Wasm / WasmGC / JS / Native)

    moon add Sam-Hui-dot/moon-pprof@0.2.0

    let base = @moon-pprof.decode_profile(base_bytes)
    let cand = @moon-pprof.decode_profile(cand_bytes)
    let policy = @moon-pprof.gate_policy(
    max_total_regression_pct=Some(15.0),
    max_func_cum_regression_pct=Some(25.0),
    )
    let diff = @moon-pprof.compare_profiles(base, cand, policy~)
    let svg = @moon-pprof.render_diff_flamegraph_svg(base, cand)
    let html = @moon-pprof.render_diff_html(base, cand, policy~)

    #2. CLI 命令

    # 查看 Top 热点(支持 text / json / md) moon run cmd/main --target wasm -- top demo/fixtures/baseline-cpu.pb.gz --sort flat --limit 15 # 导出 Brendan Gregg folded stacks moon run cmd/main --target wasm -- folded demo/fixtures/baseline-cpu.pb.gz # 生成单文件交互式 HTML 火焰图 moon run cmd/main --target wasm -- flamegraph demo/fixtures/baseline-cpu.pb.gz --html --out demo/out/baseline.html # A/B 性能回归门禁 + 屏蔽 runtime 噪音 + 红蓝差异火焰图 SVG + 离线交互 HTML 报告 moon run cmd/main --target wasm -- diff demo/fixtures/baseline-cpu.pb.gz demo/fixtures/candidate-cpu.pb.gz --hide runtime. --max-total-pct 15 --max-func-pct 25 --format md --flamegraph-out demo/out/diff.svg --html-out demo/out/diff.html # 合并多份剖析文件为规范 .pb.gz(对齐 go tool pprof -proto) moon run cmd/main --target wasm -- merge demo/fixtures/baseline-cpu.pb.gz demo/fixtures/candidate-cpu.pb.gz --out demo/out/merged.pb.gz # 按 Sample.label 标签分组统计(例如 route / tenant) moon run cmd/main --target wasm -- labels demo/fixtures/baseline-cpu.pb.gz --key route --format md

    #与官方 go tool pprof 的精确对拍

    仓库随附纯标准库 Go 基准程序 demo/gen_go_profiles.go、两份真实生成的 CPU 剖析样本(demo/fixtures/baseline-cpu.pb.gz、demo/fixtures/candidate-cpu.pb.gz)以及自动对拍脚本 demo/verify_oracle.py:

    # 零外部依赖四目标单元测试 moon test --target wasm --deny-warn moon test --target wasm-gc --deny-warn moon test --target js --deny-warn moon test --target native --deny-warn # 与官方 go tool pprof 逐函数精确对拍 + 回归门禁验证 python demo/verify_oracle.py

    实测结果:
    • CPU 对拍:baseline-cpu.pb.gz(180,000,000 ns)与 candidate-cpu.pb.gz(490,000,000 ns)全部 6 个函数的 flat / cum 与 go tool pprof -top -unit=ns 0 误差一致。
    • Heap 内存对拍:baseline-heap.pb.gz(alloc_space 3,247,944 B,22 个函数)与 candidate-heap.pb.gz(alloc_space 6,543,480 B,25 个函数)与 go tool pprof -top -sample_index=alloc_space -unit=B 逐字节 0 误差一致。
    • 多文件合并对拍:moon-pprof merge 合并两份 CPU 样本(670,000,000 ns)与 go tool pprof -proto 0 误差一致。
    • 差分门禁与过滤:diff --hide runtime. 准确屏蔽运行时帧并检出退化函数 main.slowRegressionLoop,返回退出码 1,生成差异火焰图 SVG、离线 HTML 与 Markdown 汇总表。

    #与 MoonBit 现有生态的互补关系

    • 现有 moonflame 面向纯文本 folded stack 渲染,moonsize 面向 Wasm 二进制体积统计,mooncallgrind 面向 Callgrind 文本,moonheap 面向 V8 Heap Snapshot JSON。
    • moon-pprof 填补跨语言工业标准 Google pprof(profile.proto 二进制 / .pb.gz) 解析、A/B 性能差分门禁与红蓝差异火焰图空白,既可独立用于 Go/Rust/Python/C++/Node.js 服务的离线剖析与 CI 回归拦截,也可作为全目标库被浏览器 Wasm 前端或其他 MoonBit 工具复用。

    更多验证边界与源码统计见 docs/VALIDATION.md。

    PprofError

    pub(all) suberror PprofError {
    InvalidGzip(String)
    InvalidProtobuf(String)
    InvalidProfile(String)
    InvalidInput(String)
    } derive(Eq,
    Debug
    )

    Errors raised while decompressing, decoding, validating, or analyzing pprof profiles.

    PprofError::equal

    fn PprofError::equal(PprofError, PprofError) -> Bool
    automatically derived

    PprofError::not_equal

    fn PprofError::not_equal(x : PprofError, y : PprofError) -> Bool
    automatically derived

    PprofError::to_repr

    automatically derived

    DiffEntry

    pub(all) struct DiffEntry {
    name : String
    filename : String
    baseline_flat : Int64
    candidate_flat : Int64
    delta_flat : Int64
    delta_flat_pct : Double
    baseline_cum : Int64
    candidate_cum : Int64
    delta_cum : Int64
    delta_cum_pct : Double
    baseline_cum_share_pct : Double
    candidate_cum_share_pct : Double
    delta_cum_share_pp : Double
    classification : String
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Per-function difference between a baseline profile and a candidate profile.

    DiffEntry::equal

    fn DiffEntry::equal(DiffEntry, DiffEntry) -> Bool
    automatically derived

    DiffEntry::not_equal

    fn DiffEntry::not_equal(x : DiffEntry, y : DiffEntry) -> Bool
    automatically derived

    DiffEntry::to_json

    automatically derived

    DiffEntry::to_repr

    automatically derived

    DiffReport

    pub(all) struct DiffReport {
    sample_type : String
    unit : String
    normalized : Bool
    baseline_total : Int64
    candidate_total : Int64
    delta_total : Int64
    delta_total_pct : Double
    entries : Array[DiffEntry]
    gate : GateResult
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Full differential comparison between a baseline and candidate profile.

    DiffReport::equal

    fn DiffReport::equal(DiffReport, DiffReport) -> Bool
    automatically derived

    DiffReport::not_equal

    fn DiffReport::not_equal(x : DiffReport, y : DiffReport) -> Bool
    automatically derived

    DiffReport::to_json

    automatically derived

    DiffReport::to_repr

    automatically derived

    FilterSpec

    pub(all) struct FilterSpec {
    focus : String
    ignore_pattern : String
    hide : String
    label_key : String
    label_value : String
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Stack and sample-label filtering specification (focus, ignore, hide, label).

    FilterSpec::equal

    fn FilterSpec::equal(FilterSpec, FilterSpec) -> Bool
    automatically derived

    FilterSpec::not_equal

    fn FilterSpec::not_equal(x : FilterSpec, y : FilterSpec) -> Bool
    automatically derived

    FilterSpec::to_json

    automatically derived

    FilterSpec::to_repr

    automatically derived

    FoldedStack

    pub(all) struct FoldedStack {
    stack : String
    value : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    A single folded call stack (root;caller;callee) with aggregated weight.

    FoldedStack::equal

    fn FoldedStack::equal(FoldedStack, FoldedStack) -> Bool
    automatically derived

    FoldedStack::not_equal

    fn FoldedStack::not_equal(x : FoldedStack, y : FoldedStack) -> Bool
    automatically derived

    FoldedStack::to_json

    automatically derived

    FoldedStack::to_repr

    automatically derived

    Function

    pub(all) struct Function {
    id : UInt64
    name_idx : Int64
    system_name_idx : Int64
    filename_idx : Int64
    start_line : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Symbol metadata for a profiled function.

    Function::equal

    fn Function::equal(Function, Function) -> Bool
    automatically derived

    Function::not_equal

    fn Function::not_equal(x : Function, y : Function) -> Bool
    automatically derived

    Function::to_json

    automatically derived

    Function::to_repr

    automatically derived

    FunctionStat

    pub(all) struct FunctionStat {
    name : String
    filename : String
    flat : Int64
    flat_pct : Double
    cum : Int64
    cum_pct : Double
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Per-function flat and cumulative aggregation statistics.

    FunctionStat::equal

    automatically derived

    FunctionStat::not_equal

    fn FunctionStat::not_equal(x : FunctionStat, y : FunctionStat) -> Bool
    automatically derived

    FunctionStat::to_json

    automatically derived

    FunctionStat::to_repr

    automatically derived

    GatePolicy

    pub(all) struct GatePolicy {
    max_total_regression_pct : Double?
    max_func_cum_regression_pct : Double?
    min_abs_delta : Int64
    normalize : Bool
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Threshold policy for CI performance regression gating.

    GatePolicy::equal

    fn GatePolicy::equal(GatePolicy, GatePolicy) -> Bool
    automatically derived

    GatePolicy::not_equal

    fn GatePolicy::not_equal(x : GatePolicy, y : GatePolicy) -> Bool
    automatically derived

    GatePolicy::to_json

    automatically derived

    GatePolicy::to_repr

    automatically derived

    GateResult

    pub(all) struct GateResult {
    passed : Bool
    exit_code : Int
    violations : Array[String]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Outcome of applying a GatePolicy to a DiffReport.

    GateResult::equal

    fn GateResult::equal(GateResult, GateResult) -> Bool
    automatically derived

    GateResult::not_equal

    fn GateResult::not_equal(x : GateResult, y : GateResult) -> Bool
    automatically derived

    GateResult::to_json

    automatically derived

    GateResult::to_repr

    automatically derived

    Label

    pub(all) struct Label {
    key_idx : Int64
    str_idx : Int64
    num : Int64
    num_unit_idx : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Structured key/value metadata attached to an individual sample.

    Label::equal

    fn Label::equal(Label, Label) -> Bool
    automatically derived

    Label::not_equal

    fn Label::not_equal(x : Label, y : Label) -> Bool
    automatically derived

    Label::to_json

    automatically derived

    Label::to_repr

    automatically derived

    LabelReport

    pub(all) struct LabelReport {
    sample_type : String
    unit : String
    label_key : String
    total : Int64
    matched_total : Int64
    groups : Array[LabelStat]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Grouped breakdown of a profile by a Sample.label key (e.g. HTTP route or tenant).

    LabelReport::equal

    fn LabelReport::equal(LabelReport, LabelReport) -> Bool
    automatically derived

    LabelReport::not_equal

    fn LabelReport::not_equal(x : LabelReport, y : LabelReport) -> Bool
    automatically derived

    LabelReport::to_json

    automatically derived

    LabelReport::to_repr

    automatically derived

    LabelStat

    pub(all) struct LabelStat {
    label_value : String
    value : Int64
    pct : Double
    sample_count : Int
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Aggregated metric total for one value of a Sample.label key.

    LabelStat::equal

    fn LabelStat::equal(LabelStat, LabelStat) -> Bool
    automatically derived

    LabelStat::not_equal

    fn LabelStat::not_equal(x : LabelStat, y : LabelStat) -> Bool
    automatically derived

    LabelStat::to_json

    automatically derived

    LabelStat::to_repr

    automatically derived

    Line

    pub(all) struct Line {
    function_id : UInt64
    line : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Source line reference inside a Location (ordered leaf-first when inlined).

    Line::equal

    fn Line::equal(Line, Line) -> Bool
    automatically derived

    Line::not_equal

    fn Line::not_equal(x : Line, y : Line) -> Bool
    automatically derived

    Line::to_json

    automatically derived

    Line::to_repr

    automatically derived

    Location

    pub(all) struct Location {
    id : UInt64
    mapping_id : UInt64
    address : UInt64
    lines : Array[Line]
    is_folded : Bool
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Code location referenced by samples, optionally expanding to inlined lines.

    Location::equal

    fn Location::equal(Location, Location) -> Bool
    automatically derived

    Location::not_equal

    fn Location::not_equal(x : Location, y : Location) -> Bool
    automatically derived

    Location::to_json

    automatically derived

    Location::to_repr

    automatically derived

    Mapping

    pub(all) struct Mapping {
    id : UInt64
    memory_start : UInt64
    memory_limit : UInt64
    file_offset : UInt64
    filename_idx : Int64
    build_id_idx : Int64
    has_functions : Bool
    has_filenames : Bool
    has_line_numbers : Bool
    has_inline_frames : Bool
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Binary image mapping metadata for a profiled process.

    Mapping::equal

    fn Mapping::equal(Mapping, Mapping) -> Bool
    automatically derived

    Mapping::not_equal

    fn Mapping::not_equal(x : Mapping, y : Mapping) -> Bool
    automatically derived

    Mapping::to_json

    automatically derived

    Mapping::to_repr

    automatically derived

    Profile

    pub(all) struct Profile {
    sample_types : Array[ValueType]
    samples : Array[Sample]
    mappings : Array[Mapping]
    locations : Array[Location]
    functions : Array[Function]
    string_table : Array[String]
    drop_frames : Int64
    keep_frames : Int64
    time_nanos : Int64
    duration_nanos : Int64
    period_type : ValueType?
    period : Int64
    comments : Array[Int64]
    default_sample_type : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Decoded Google perftools.profiles.Profile message (profile.proto).

    Profile::equal

    fn Profile::equal(Profile, Profile) -> Bool
    automatically derived

    Profile::not_equal

    fn Profile::not_equal(x : Profile, y : Profile) -> Bool
    automatically derived

    Profile::string_at

    fn Profile::string_at(self : Profile, index : Int64) -> String raise PprofError

    Look up a string in profile.string_table with bounds checking.

    Profile::to_json

    automatically derived

    Profile::to_repr

    automatically derived

    Sample

    pub(all) struct Sample {
    location_ids : Array[UInt64]
    values : Array[Int64]
    labels : Array[Label]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    A single recorded stack trace (location_ids leaf-first) with parallel metric values.

    Sample::equal

    fn Sample::equal(Sample, Sample) -> Bool
    automatically derived

    Sample::not_equal

    fn Sample::not_equal(x : Sample, y : Sample) -> Bool
    automatically derived

    Sample::to_json

    automatically derived

    Sample::to_repr

    automatically derived

    SortBy

    pub(all) enum SortBy {
    Flat
    Cum
    } derive(Eq,
    Debug
    )

    Sort criterion for compute_top.

    SortBy::equal

    fn SortBy::equal(SortBy, SortBy) -> Bool
    automatically derived

    SortBy::not_equal

    fn SortBy::not_equal(x : SortBy, y : SortBy) -> Bool
    automatically derived

    SortBy::to_repr

    automatically derived

    TopReport

    pub(all) struct TopReport {
    sample_type : String
    unit : String
    total : Int64
    shown_total : Int64
    sample_count : Int
    duration_nanos : Int64
    entries : Array[FunctionStat]
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Top-N aggregation report for a single profile and metric.

    TopReport::equal

    fn TopReport::equal(TopReport, TopReport) -> Bool
    automatically derived

    TopReport::not_equal

    fn TopReport::not_equal(x : TopReport, y : TopReport) -> Bool
    automatically derived

    TopReport::to_json

    automatically derived

    TopReport::to_repr

    automatically derived

    ValueType

    pub(all) struct ValueType {
    type_idx : Int64
    unit_idx : Int64
    } derive(Eq,
    Debug
    ,
    ToJson
    )

    Describes the type and measurement unit of a sample value (e.g. cpu / nanoseconds).

    ValueType::equal

    fn ValueType::equal(ValueType, ValueType) -> Bool
    automatically derived

    ValueType::not_equal

    fn ValueType::not_equal(x : ValueType, y : ValueType) -> Bool
    automatically derived

    ValueType::to_json

    automatically derived

    ValueType::to_repr

    automatically derived

    collapse_stacks

    fn collapse_stacks(profile : Profile, sample_type? : String, filter? : String, spec? : FilterSpec?) -> Array[FoldedStack] raise PprofError

    Collapse all samples into Brendan Gregg folded call stacks (root;caller;callee).

    compare_profiles

    fn compare_profiles(baseline : Profile, candidate : Profile, sample_type? : String, policy? : GatePolicy, limit? : Int, filter? : String, spec? : FilterSpec?) -> DiffReport raise PprofError

    Compare two profiles on the same metric, producing per-function deltas and CI gate results.

    compute_top

    fn compute_top(profile : Profile, sample_type? : String, sort_by? : SortBy, limit? : Int, filter? : String, spec? : FilterSpec?) -> TopReport raise PprofError

    Compute per-function flat and cum statistics aligned with go tool pprof -top.

    decode_profile

    fn decode_profile(data : Bytes) -> Profile raise PprofError

    Decode and validate a Google pprof binary profile (.pb or gzipped .pb.gz).

    encode_profile

    fn encode_profile(profile : Profile, gzip? : Bool) -> Bytes

    Encode a Profile into canonical profile.proto binary bytes (optionally gzip-compressed).

    error_message

    fn error_message(error : Error) -> String

    Convert any error into a concise human-readable diagnostic message.

    filter_spec

    fn filter_spec(focus? : String, ignore_pattern? : String, hide? : String, label_key? : String, label_value? : String) -> FilterSpec

    Build a FilterSpec for focus, ignore, hide, and Sample.label slicing.

    gate_policy

    fn gate_policy(max_total_regression_pct? : Double?, max_func_cum_regression_pct? : Double?, min_abs_delta? : Int64, normalize? : Bool) -> GatePolicy

    Construct a GatePolicy with optional total and per-function cumulative regression limits.

    group_by_label

    fn group_by_label(profile : Profile, label_key : String, sample_type? : String, spec? : FilterSpec?) -> LabelReport raise PprofError

    Group profile metric totals by the values of a Sample.label key (e.g. route, tenant).

    gunzip_if_needed

    fn gunzip_if_needed(data : Bytes) -> Bytes raise PprofError

    Decompress gzip-encoded bytes or return raw protobuf bytes unchanged.

    is_gzip

    fn is_gzip(data : Bytes) -> Bool

    Return true when data begins with the RFC 1952 gzip magic header (0x1F 0x8B).

    merge_profiles

    fn merge_profiles(profiles : Array[Profile]) -> Profile raise PprofError

    Merge multiple compatible Profile instances into a single deduplicated Profile.

    All input profiles must declare identical (type, unit) sample_types in the same order. String tables, mappings, functions, locations, and identical (stack, labels) samples are merged deterministically so numeric totals are strictly conserved.

    render_diff_flamegraph_svg

    fn render_diff_flamegraph_svg(baseline : Profile, candidate : Profile, sample_type? : String, title? : String, width? : Int, min_width_px? : Double, normalize? : Bool, filter? : String, spec? : FilterSpec?) -> String raise PprofError

    Render a Brendan Gregg red/blue Differential Flame Graph SVG comparing baseline vs candidate.

    render_diff_html

    fn render_diff_html(baseline : Profile, candidate : Profile, sample_type? : String, title? : String, policy? : GatePolicy, limit? : Int, filter? : String, spec? : FilterSpec?) -> String raise PprofError

    Render a complete interactive single-file HTML differential report comparing baseline vs candidate.

    render_diff_markdown

    fn render_diff_markdown(report : DiffReport) -> String

    Render a DiffReport as GitHub-flavored Markdown (ready for CI Step Summaries).

    render_diff_text

    fn render_diff_text(report : DiffReport) -> String

    Render a DiffReport as compact plain text suitable for terminal output.

    render_flamegraph_svg

    fn render_flamegraph_svg(profile : Profile, sample_type? : String, title? : String, width? : Int, min_width_px? : Double, filter? : String, spec? : FilterSpec?) -> String raise PprofError

    Render an interactive-ready native SVG flame graph for a single profile.

    render_folded

    fn render_folded(stacks : Array[FoldedStack]) -> String

    Render folded stacks in standard frame1;frame2 value line format.

    render_interactive_html

    fn render_interactive_html(title : String, svg : String, summary_html : String) -> String

    Render a self-contained offline interactive HTML report with flamegraph search, zoom, and summary table.

    render_label_markdown

    fn render_label_markdown(report : LabelReport) -> String

    Render a LabelReport as a GitHub-flavored Markdown table.

    render_label_text

    fn render_label_text(report : LabelReport) -> String

    Render a LabelReport as compact plain text.

    render_top_html

    fn render_top_html(profile : Profile, sample_type? : String, title? : String, limit? : Int, filter? : String, spec? : FilterSpec?) -> String raise PprofError

    Render a complete interactive single-file HTML report for a single profile.

    render_top_markdown

    fn render_top_markdown(report : TopReport) -> String

    Render a TopReport as a GitHub-flavored Markdown table.

    render_top_text

    fn render_top_text(report : TopReport) -> String

    Render a TopReport as compact plain text suitable for terminal output.

    resolve_sample_type

    fn resolve_sample_type(profile : Profile, sample_type? : String) -> (Int, String, String) raise PprofError

    Resolve a sample type name (or default following go tool pprof semantics) to (index, name, unit).

    sample_type_names

    fn sample_type_names(profile : Profile) -> Array[(String, String)] raise PprofError

    List all declared (type, unit) sample metric pairs in a profile.

    validate_profile

    fn validate_profile(profile : Profile) -> Unit raise PprofError

    Validate invariants mandated by profile.proto (string table index 0, value counts, indices).