samply - Sampling Profiler with Firefox Profiler UI Cheatsheet
samply is a cross-platform command-line sampling profiler for macOS, Linux, and Windows. It samples stack traces of a command or a running process (default ~1000 Hz) and then serves the results to the Firefox Profiler web UI — a mature, interactive front end with flame graphs, stack charts, a call tree, and per-thread timelines. It profiles native code (C/C++/Rust/Go) and other languages that emit standard stack info, with no code changes required.
Installation
| Method | Command |
|---|
| Cargo | cargo install --locked samply |
| Binary | download from the GitHub Releases page |
| Linux perf event access | may need sysctl kernel.perf_event_paranoid=1 (or lower) |
| Verify | samply --version |
Basic Usage
| Command | Description |
|---|
samply record ./my-program args | Profile a command, then open the UI |
samply record -- cargo run --release | Profile after -- (pass flags through) |
samply record --pid 1234 | Profile an already-running process |
samply load profile.json.gz | Re-open a saved profile in the UI |
samply --help | Full option list |
Recording Options
| Option | Description |
|---|
-r, --rate N | Sampling rate in Hz (default ~1000) |
-o, --output FILE | Save the profile to a file |
--save-only | Record without launching the browser UI |
-p, --pid PID | Attach to a running process |
-d, --duration SECS | Profile for a fixed duration |
--reuse-threads | Thread handling tweak for some workloads |
-- | Everything after is the command + its args |
The Firefox Profiler UI
After recording, samply opens a local Firefox Profiler view. Key panels:
| Panel | Shows |
|---|
| Flame graph | Aggregated stacks (where time is spent) |
| Stack chart | Time on the x-axis, stacks stacked vertically |
| Call tree | Top-down / bottom-up hierarchy with self/total time |
| Marker chart | Events over time (if present) |
| Timeline | Per-thread activity; select a range to focus |
| UI action | Use |
|---|
| Select a time range | Focus analysis on part of the run |
| Invert call stack | Find hot leaf functions (self time) |
| Search | Filter the call tree by function name |
| Share/export | Save or upload the profile |
Workflow Tips
| Goal | Approach |
|---|
| Find CPU hot paths | Record, open flame graph, look for wide frames |
| Find a specific slow phase | Select that time range in the timeline |
| Compare builds | Save profiles and load side by side |
| Reduce noise | Profile release builds with debug info (debug = true) |
Common Workflows
# Profile a Rust release build (keep symbols with debug info)
samply record -- cargo run --release
# Profile a running server for 20 seconds
samply record --pid $(pgrep -n myserver) -d 20
# Record headless in CI, inspect the artifact later
samply record --save-only -o prof.json.gz ./bench
samply load prof.json.gz
samply vs Other Profilers
| Aspect | samply | perf + FlameGraph | hotspot |
|---|
| Platforms | macOS/Linux/Windows | Linux | Linux |
| UI | Firefox Profiler (rich) | Static SVG | Qt GUI |
| Setup | Single binary | Multiple tools | GUI install |
| Best for | Cross-platform, interactive | Scripted Linux profiling | Qt/perf GUI users |
Resources