Crate jemalloc_ctl [] [src]

jemalloc control and introspection.

jemalloc offers a powerful introspection and control interface through the mallctl function. It can be used to tune the allocator, take heap dumps, and retrieve statistics. This crate provides a typed API over that interface.

While mallctl takes a string to specify an operation (e.g. stats.allocated or stats.arenas.15.muzzy_decay_ms`), the overhead of repeatedly parsing those strings is not ideal. Fortunately, jemalloc offers the ability to translate the string ahead of time into a "Management Information Base" (MIB) to speed up future lookups.

This crate provides a type for each mallctl operation. Its constructor performs the MIB lookup, so the struct should be saved if the same operation is going to be repeatedly performed.

Warning

This library is forced to assume that jemalloc is present and simply link to some of its functions. This will result in linker errors when building a binary that doesn't actually use jemalloc as its allocator.

Examples

Repeatedly printing allocation statistics:

use std::thread;
use std::time::Duration;
use jemalloc_ctl::Epoch;
use jemalloc_ctl::stats::{Allocated, Resident};

let epoch = Epoch::new().unwrap();
let allocated = Allocated::new().unwrap();
let resident = Resident::new().unwrap();

loop {
    // many statistics are cached and only updated when the epoch is advanced.
    epoch.advance().unwrap();

    let allocated = allocated.get().unwrap();
    let resident = resident.get().unwrap();
    println!("{} bytes allocated/{} bytes resident", allocated, resident);
    thread::sleep(Duration::from_secs(10));
}

Modules

arenas

Arena operations.

config

Information about the jemalloc compile-time configuration

opt

Information about the run-time jemalloc configuration.

stats

Global allocator statistics.

stats_print

Bulk statistics output.

thread

Thread specific operations.

Structs

Epoch

A type providing access to the jemalloc epoch.

Version

A type providing access to the jemalloc version string.