memory-stats 1.2.0

A cross-platform memory profiler for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::sync::atomic::{AtomicUsize, Ordering};

pub static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0);

/// Grabs the value of the SC_PAGESIZE if needed.
pub fn load_page_size() -> Option<()> {
    if PAGE_SIZE.load(Ordering::Relaxed) == 0 {
        let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) };
        if page_size == -1 {
            // sysconf returned error
            return None;
        } else {
            PAGE_SIZE.store(page_size as usize, Ordering::Relaxed);
        }
    }
    Some(())
}