Zero-Cost Abstractions: Memory Profiling in Rust
Examining telemetry overlays and customized jemalloc hooks to diagnose unexpected memory allocation patterns in bare-metal environments. We isolate stack vs. heap allocation boundaries without runtime overhead.
// Hooking runtime stats directly from jemalloc arena
unsafe fn profile_heap_extent() -> Result<ArenaStat, AllocErr> {
let epoch = jemalloc_ctl::epoch::mib()?;
epoch.advance()?;
let allocated = jemalloc_ctl::stats::allocated::mib()?.read()?;
Ok(ArenaStat { bytes_in_use: allocated })
}