Pure-MoonBit Google pprof (profile.proto) parser, differential profiler, CI regression gate, and interactive flamegraph renderer
moon add Sam-Hui-dot/moon-pprof@0.2.0let 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~)# 查看 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# 零外部依赖四目标单元测试
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.pypub(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)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)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)fn collapse_stacks(profile : Profile, sample_type? : String, filter? : String, spec? : FilterSpec?) -> Array[FoldedStack] raise PprofErrorfn compare_profiles(baseline : Profile, candidate : Profile, sample_type? : String, policy? : GatePolicy, limit? : Int, filter? : String, spec? : FilterSpec?) -> DiffReport raise PprofErrorfn compute_top(profile : Profile, sample_type? : String, sort_by? : SortBy, limit? : Int, filter? : String, spec? : FilterSpec?) -> TopReport raise PprofErrorfn error_message(error : Error) -> Stringfn filter_spec(focus? : String, ignore_pattern? : String, hide? : String, label_key? : String, label_value? : String) -> FilterSpecfn gate_policy(max_total_regression_pct? : Double?, max_func_cum_regression_pct? : Double?, min_abs_delta? : Int64, normalize? : Bool) -> GatePolicyfn group_by_label(profile : Profile, label_key : String, sample_type? : String, spec? : FilterSpec?) -> LabelReport raise PprofErrorfn is_gzip(data : Bytes) -> Boolfn 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 PprofErrorfn render_diff_html(baseline : Profile, candidate : Profile, sample_type? : String, title? : String, policy? : GatePolicy, limit? : Int, filter? : String, spec? : FilterSpec?) -> String raise PprofErrorfn render_flamegraph_svg(profile : Profile, sample_type? : String, title? : String, width? : Int, min_width_px? : Double, filter? : String, spec? : FilterSpec?) -> String raise PprofErrorfn render_interactive_html(title : String, svg : String, summary_html : String) -> Stringfn render_top_html(profile : Profile, sample_type? : String, title? : String, limit? : Int, filter? : String, spec? : FilterSpec?) -> String raise PprofErrorfn resolve_sample_type(profile : Profile, sample_type? : String) -> (Int, String, String) raise PprofErrorInstall
Download zipPure-MoonBit Google pprof (profile.proto) parser, differential profiler, CI regression gate, and interactive flamegraph renderer