#![cfg_attr(
feature = "stats",
doc = r##"
# Examples
Repeatedly printing allocation statistics:
```no_run
use std::thread;
use std::time::Duration;
use tikv_jemalloc_ctl::{stats, epoch};
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_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:
```no_run
use std::thread;
use std::time::Duration;
use tikv_jemalloc_ctl::{stats, epoch};
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_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));
}
}
```
"##
)]
#![allow(renamed_and_removed_lints)]
#![deny(missing_docs, broken_intra_doc_links)]
#![cfg_attr(not(feature = "use_std"), no_std)]
#[cfg(test)]
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use crate::std::{fmt, mem, num, ops, ptr, result, slice, str};
#[cfg(not(feature = "use_std"))]
use core as std;
#[cfg(feature = "use_std")]
use std;
#[macro_use]
mod macros;
pub mod arenas;
pub mod config;
mod error;
mod keys;
pub mod opt;
#[cfg(feature = "profiling")]
pub mod profiling;
pub mod raw;
#[cfg(feature = "stats")]
pub mod stats;
#[cfg(feature = "use_std")]
pub mod stats_print;
pub mod thread;
pub use error::{Error, Result};
pub use keys::{Access, AsName, Mib, MibStr, Name};
option! {
version[ str: b"version\0", str: 1 ] => &'static str |
ops: r |
docs:
mib_docs: }
option! {
background_thread[ str: b"background_thread\0", non_str: 1 ] => bool |
ops: r,w,u |
docs:
mib_docs: }
option! {
max_background_threads[ str: b"max_background_threads\0", non_str: 1 ] => libc::size_t |
ops: r, w, u |
docs:
mib_docs: }
option! {
epoch[ str: b"epoch\0", non_str: 1 ] => u64 |
ops: r, w, u |
docs:
mib_docs: }
impl epoch {
pub fn advance() -> crate::error::Result<u64> {
Self::update(1)
}
}
impl epoch_mib {
pub fn advance(self) -> crate::error::Result<u64> {
self.0.update(1)
}
}