jemalloc_pprof
Convert jemalloc heap profiles to pprof format for memory leak and OOM debugging
Repository Health
Technical Analysis
jemalloc_pprof converts heap profiling data collected by the jemalloc memory allocator into Google’s pprof protocol buffer format, so Rust services can plug memory profiling into the same tooling ecosystem (pprof viewers, flamegraph generators, continuous profiling platforms) already used across Go and other pprof-native languages. It was originally developed inside Materialize and later extracted into this standalone library in collaboration with Polar Signals, the company behind the Parca continuous profiling project.
The crate works by interacting with jemalloc via tikv-jemalloc-ctl to trigger and read heap profile dumps, then translating jemalloc’s native profile format into pprof’s protobuf schema (via the sibling mappings and util/pprof_util workspace crates), optionally producing flamegraphs directly or symbolizing stack frames. It requires switching the process’s global allocator to jemalloc via tikv-jemallocator with its profiling feature enabled, and currently only supports Linux.
What You Get
- Conversion of jemalloc heap profile dumps into Google’s pprof protobuf format for use with standard pprof tooling
- Direct flamegraph generation from heap profiles via the
flamegraphfeature - Stack frame symbolization support via the
symbolizefeature for human-readable profile output - A workspace of focused sibling crates (
mappingsfor memory-map parsing,util/pprof_utilfor shared pprof encoding) that other profiling tools can reuse independently - A capi crate exposing the conversion functionality to non-Rust callers via a C ABI
Common Use Cases
- Diagnosing a Rust service’s memory leak by capturing and converting jemalloc heap profiles for visual inspection in pprof or Parca
- Investigating recurring OOM kills in a containerized Rust service by feeding periodic heap snapshots into continuous profiling infrastructure
- Continuously exporting heap profiles from production Rust services to Polar Signals Cloud or a self-hosted Parca instance
- Generating flamegraphs of memory allocation hotspots during performance/memory optimization work
Under The Hood
Architecture The crate (src/lib.rs) is deliberately thin — it drives tikv-jemalloc-ctl to trigger jemalloc heap dumps, then delegates the actual profile translation to two sibling workspace crates: mappings (parsing /proc/self/maps-style memory mapping info needed to attribute addresses to binaries/libraries) and util, published separately as pprof_util (shared pprof protobuf encoding logic used across Polar Signals’ profiling tools). A separate capi crate wraps the conversion logic behind a C ABI, and an example crate demonstrates end-to-end usage, giving the workspace a clean core-plus-bindings-plus-example structure.
Tech Stack Rust 2021 edition, Linux-only. Built on tikv-jemalloc-ctl (the interface to jemalloc’s control/stats API) and prost for pprof protobuf encoding/decoding, with optional inferno (flamegraph rendering) and backtrace (symbolization) pulled in behind the flamegraph/symbolize features respectively. Requires the host application to also depend on tikv-jemallocator with its profiling feature to actually enable jemalloc’s profiling hooks.
Code Quality The core src/lib.rs is compact at under 200 lines, with the bulk of the conversion complexity factored out into the mappings and util crates rather than inlined — a sign of deliberate separation of concerns rather than a monolithic implementation. GitHub activity shows infrequent maintenance commits, consistent with a narrowly-scoped utility crate that reaches feature-completeness rather than needing continuous churn.
API Design Because this crate exists specifically to interoperate with an established external format (pprof) and a specific allocator (jemalloc), its API surface is necessarily narrow and tightly coupled to both: users must already be running jemalloc via tikv-jemallocator with profiling enabled before this crate does anything useful. The README is explicit and upfront about this prerequisite plus the Linux-only requirement, which keeps expectations realistic even though it does narrow the audience versus a more general-purpose profiling tool.
Used by 2 apps in this directory
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
PostHog
Analytics · Monitoring · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.