[−][src]Crate jemalloc_ctl
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. Calling
$op::{read(), write(x), update(x)}
on the type calls mallctl
with the
string-based API. If the operation will be repeatedly performed, a MIB for
the operation can be obtained using $op.mib()
.
Examples
Repeatedly printing allocation statistics:
extern crate jemallocator; extern crate jemalloc_ctl; use std::thread; use std::time::Duration; use jemalloc_ctl::{stats, epoch}; #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; fn main() { loop { // many statistics are cached and only updated when the epoch is advanced. epoch::advance().unwrap(); let allocated = stats::allocated::read().unwrap(); let resident = stats::resident::read().unwrap(); println!("{} bytes allocated/{} bytes resident", allocated, resident); thread::sleep(Duration::from_secs(10)); } }
Doing the same with the MIB-based API:
extern crate jemallocator; extern crate jemalloc_ctl; use std::thread; use std::time::Duration; use jemalloc_ctl::{stats, epoch}; #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; fn main() { let e = epoch::mib().unwrap(); let allocated = stats::allocated::mib().unwrap(); let resident = stats::resident::mib().unwrap(); loop { // many statistics are cached and only updated when the epoch is advanced. e.advance().unwrap(); let allocated = allocated.read().unwrap(); let resident = resident.read().unwrap(); println!("{} bytes allocated/{} bytes resident", allocated, resident); thread::sleep(Duration::from_secs(10)); } }
Modules
arenas | Arena operations. |
config |
|
opt |
|
raw | Raw |
stats | Global allocator statistics. |
thread | Thread specific operations. |
Structs
Error | Errors of the |
Mib | Management Information Base of a non-string value. |
MibStr | Management Information Base of a string value. |
Name | A |
background_thread | State of internal background worker threads. |
background_thread_mib | See |
epoch |
|
epoch_mib | See |
max_background_threads | Maximum number of background threads that will be created. |
max_background_threads_mib | |
version |
|
version_mib | See |
Traits
Access | Safe read access to the MALLCTL NAMESPACE. |
AsName | Converts a null-terminated byte-string into a |
Type Definitions
Result | Result type |