eval_stack/
utils.rs

1use std::fs;
2
3pub fn get_memory_usage(pid: u32) -> Option<u64> {
4    let statm_path = format!("/proc/{}/statm", pid);
5    let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) as u64 };
6    if let Ok(contents) = fs::read_to_string(statm_path) {
7        let resident = contents.split_whitespace().nth(1)?;
8        let memory = resident.parse::<u64>().ok()? * page_size;
9        return Some(memory);
10    }
11    None
12}