Generating flamegraphs
Enable profiling with the--profile flag:
Output formats
Choose between HTML and SVG formats:- HTML (Interactive)
- SVG (Static)
Generate a standalone interactive HTML file with hover tooltips and zoom:File:
<transaction-hash>.flamegraph.htmlHTML is the default format and provides the best user experience. Use SVG only if you need to embed the flamegraph in other tools or documents.
Understanding flamegraphs
Flamegraphs visualize the call stack over time:Reading the graph
- X-axis (width): Proportion of time/resources consumed
- Y-axis (height): Call stack depth (bottom = entry point, top = leaf calls)
- Colors: Different contract functions and host operations
- Frame size: Larger frames = more time/resources consumed
Example structure
transferconsumed 40% of total resources- Within
transfer,checkandupdateeach used 20% mintconsumed 30%, all withincreate_token
Interactive features
Hover tooltips
Hover over any frame to see detailed information:Click-to-zoom
Click any frame to zoom in and focus on that section:Zooming helps you focus on specific hot paths without visual clutter from other parts of the execution.
Search and highlight
Find specific functions or operations:
Search is case-insensitive:
Profiling metrics
CPU consumption
Flamegraphs show CPU instruction counts for each operation:- Contract execution: WASM instructions executed
- Host functions: Built-in Stellar operations
- Storage operations: Read/write costs
- Cryptographic operations: Signature verification, hashing
Memory consumption
Memory usage is tracked for:- WASM linear memory: Contract heap allocations
- Host environment: Temporary buffers and state
- Storage entries: Ledger entry sizes
Analyzing performance issues
Identifying hot paths
Look for the widest frames at each level:Common performance patterns
Excessive storage reads
Deep call stacks
Repeated operations
Profiling workflow
Dark mode support
Flamegraphs automatically adapt to your system theme:- Light mode
- Dark mode
- White background
- Dark text
- Bright colors for frames
Dark mode is detected automatically using CSS media queries. No configuration needed.
Comparing performance
Profile multiple transactions to compare performance:- Frame width differences show performance improvements
- Removed frames indicate eliminated operations
- New frames show added functionality
Export and sharing
Flamegraphs are standalone files that can be:- Shared with team members: Send the HTML file directly
- Embedded in documentation: Include SVG format in docs
- Archived for history: Store with transaction data for future reference
- Opened offline: No external dependencies or network requests
Browser compatibility
Interactive HTML flamegraphs work in all modern browsers:- Chrome/Edge 88+
- Firefox 78+
- Safari 14+
- Opera 74+
Tips for profiling
Use profiling early
Profile during development, not just when you have problems:- Catch performance issues before deployment
- Understand baseline costs of operations
- Compare different implementation approaches
Focus on hot paths
Don’t optimize everything:- Target the widest frames (biggest impact)
- Ignore thin frames (minimal impact)
- Consider code complexity vs performance gain
Profile realistic transactions
Use representative data:- Real-world transaction sizes
- Typical argument values
- Expected contract state
Combine with other tools
Use profiling alongside:- Interactive trace viewer for step-by-step analysis
- Source mapping for exact code locations
- Unit tests to isolate specific functions
Next steps
- Learn about Source mapping to see source code in profiles
- Use the Interactive trace viewer for detailed step analysis
- Set up Offline analysis to profile without network access