rpprof
rpprof is a CPU and memory profiler for Rust programs. It is a fork of tikv/pprof-rs, created to apply needed dependency updates and bug fixes after upstream development remained stale for nearly a year.
rpprof refreshes dependency trees to address known advisories, fixes signal handling and unwinding edge cases, and adds observability for dropped samples.
Key Changes and Improvements
- Dependency and Security Updates: Refreshed dependency trees to resolve security advisories flagged by
cargo-deny(includingmemmap2,quick-xml,anyhow,bytes,rand,adler, andcrossbeam-epoch). - Missed Sample Observability: Built-in atomic counter (
guard.missed_samples()/Profiler::missed_samples()) tracking sampling ticks dropped due to lock contention in the signal handler. Missed sample counts are also embedded in generated pprof protobuf profiles. - Stray SIGPROF Protection: Sets
SIG_IGNwhen unregistering the signal handler if the previous disposition was default, preventing trailing timer signals from aborting the process. - macOS Context Alignment: Safe unaligned reads of
ucontext_tfields in signal handlers to prevent debug assertions on macOS. - Async-Signal-Safe Address Validation: Uses direct
libcsystem calls inaddr_validatewithout creating temporary slice references or relying on higher-level file descriptor abstractions. - Modern Ecosystem Support: Compatible with Rust 2024 Edition, with updated dependency ranges across
nix,prost,object,inferno, andcriterion. - Dual Licensed: MIT OR Apache-2.0.
Usage
Add rpprof to your Cargo.toml:
[]
= { = "0.16", = ["flamegraph", "prost-codec"] }
Basic Profiling
use File;
Features
| Feature | Description |
|---|---|
cpp (default) |
Enables C++ symbol demangling via symbolic-demangle. |
flamegraph |
Enables SVG flamegraph generation via inferno. |
prost-codec |
Enables Google pprof protobuf profile format generation via prost. |
protobuf-codec |
Enables Google pprof protobuf profile format generation via protobuf crate. |
framehop-unwinder |
Stack unwinding using framehop (fast, allocation-free unwinding). |
frame-pointer |
Stack unwinding using frame pointers (requires building std with frame pointers). |
criterion |
Custom profiler integration for criterion benchmarks. |
perfmaps |
Support for /tmp/perf-<pid>.map symbol resolution. |
Generating Flamegraphs
With the flamegraph feature enabled:
if let Ok = guard.report.build
Custom options (e.g. image width):
if let Ok = guard.report.build
Google pprof Protobuf Output
With prost-codec enabled, rpprof outputs standard profile.proto protobuf profiles:
use File;
use Write;
use Message;
if let Ok = guard.report.build
You can then visualize or analyze the profile with go tool pprof:
pprof -http=:8080 profile.pb
Frame Post-Processor
Before report generation, a frames_post_processor can normalize or rewrite frame and thread names:
if let Ok = guard
.report
.frames_post_processor
.build
Criterion Integration
With the criterion and flamegraph features enabled:
use ;
use ;
criterion_group!
criterion_main!;
Minimum Supported Rust Version (MSRV)
Rust 1.88.0 (Rust 2024 Edition) or higher. Target/development toolchain is Rust 1.98.
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.