This implementation adds flame graph export capability to the soroban-debug profile command, allowing developers to generate interactive performance visualization artifacts alongside traditional hotspot reports.
- inferno (0.11): Rust library for flame graph rendering and SVG generation
Implements FlameGraphGenerator with the following capabilities:
-
from_report(): Converts OptimizationReport into flame graph stack format- Creates stacks for each function based on total CPU instructions
- Generates sub-stacks for operations and storage accesses
- Normalizes counts for proper visualization
-
to_collapsed_stack_format(): Converts stacks to collapsed format (text-based intermediate)- Standard format compatible with Flamegraph tools
function;operation;detail countformat
-
generate_svg(): Renders SVG flame graph directly- 1200x800 default dimensions (customizable)
- 12pt default font size
- Full interactive SVG output
-
write_collapsed_stack_file(): Exports intermediate format to file -
write_svg_file(): Exports rendered SVG to file
Added four new options to src/cli/args.rs:
--flamegraph <FLAMEGRAPH> // Path to SVG output
--flamegraph-stacks <STACKS> // Path to collapsed stack format output
--flamegraph-width <WIDTH> // SVG width (default: 1200)
--flamegraph-height <HEIGHT> // SVG height (default: 800)Modified src/cli/commands.rs::profile() to:
- Generate flame graphs after analysis when
--flamegraphflag is provided - Export collapsed stack format when
--flamegraph-stacksflag is provided - Support both formats simultaneously
- Log output paths for user confirmation
Created tests/cli/flamegraph_tests.rs with:
test_profile_flamegraph_svg_export: Validates SVG generationtest_profile_flamegraph_stacks_export: Validates collapsed format exporttest_profile_flamegraph_both_exports: Validates simultaneous exporttest_profile_flamegraph_custom_dimensions: Validates custom size parameters
- Stack generation from mock reports
- Collapsed format formatting
- File output operations
Updated man/man1/soroban-debug-profile.1 with:
- New flame graph options in SYNOPSIS
- Detailed descriptions for each new parameter
- Extended DESCRIPTION section noting visualization capability
soroban-debug profile \
--contract contract.wasm \
--function init \
--flamegraph profile.svgsoroban-debug profile \
--contract contract.wasm \
--function main \
--flamegraph-stacks profile.stackssoroban-debug profile \
--contract contract.wasm \
--function execute \
--flamegraph profile.svg \
--flamegraph-width 1600 \
--flamegraph-height 1000soroban-debug profile \
--contract contract.wasm \
--function transfer \
--output report.md \
--flamegraph profile.svg \
--flamegraph-stacks profile.stacksFlame graphs are generated from:
- Function-level stacks: Each function gets a stack proportional to its CPU cost
- Operation stacks: Expensive operations appear as sub-stacks under their function
- Storage access stacks: Storage operations tracked as separate branches
- Uses CPU instructions as primary metric
- Normalizes to reasonable sampling counts for visualization
- Handles edge cases (zero costs, single samples)
- Collapsed stack format is compatible with:
flamegraph-rstools- Firefox Profiler import
- Other standard flamegraph viewers
- Minimal comments: Code is self-documenting through clear naming
- Zero redundancy: Reuses existing report structures
- Optimized: Efficient stack generation and formatting
- Well-tested: Unit and integration tests included
✅ Profile emits flame graph artifacts (SVG) ✅ Profile emits intermediate format (collapsed stacks) ✅ Tests added for new functionality ✅ User-facing documentation updated (man page, args help) ✅ Optional feature (doesn't affect existing workflow)