use super::*;
pub(super) fn old_get_memory(entry: &mut ProcessInner, parts: &Parts, info: &SystemInfo) {
entry.memory = parts.resident_set_size.saturating_mul(info.page_size_b);
entry.virtual_memory = parts.virtual_size
}
pub(super) fn slice_to_nb(s: &[u8]) -> u64 {
let mut nb: u64 = 0;
for c in s {
nb = nb * 10 + (c - b'0') as u64;
}
nb
}
pub(super) fn get_memory(
proc_dir: &mut ProcDir<'_>,
entry: &mut ProcessInner,
info: &SystemInfo,
buf: &mut Vec<u8>,
) -> bool {
if !proc_dir.read_into(c"statm", buf) {
return false;
}
let mut parts = buf.split(|c| *c == b' ');
entry.virtual_memory = parts
.next()
.map(slice_to_nb)
.unwrap_or(0)
.saturating_mul(info.page_size_b);
entry.memory = parts
.next()
.map(slice_to_nb)
.unwrap_or(0)
.saturating_mul(info.page_size_b);
true
}
#[allow(clippy::too_many_arguments)]
pub(super) fn update_time_and_memory(
proc_dir: &mut ProcDir<'_>,
entry: &mut ProcessInner,
parts: &Parts,
uptime: u64,
info: &SystemInfo,
refresh_kind: ProcessRefreshKind,
buf: &mut Vec<u8>,
) {
{
#[allow(clippy::collapsible_if)]
if refresh_kind.memory() {
if !get_memory(proc_dir, entry, info, buf) {
old_get_memory(entry, parts, info);
}
}
set_time(entry, parts.user_time, parts.system_time);
entry.run_time = uptime.saturating_sub(entry.start_time_without_boot_time);
}
}