Skip to content

Commit

Permalink
Merge pull request #28 from lambdalisue/dependabot/cargo/procfs-0.16.0
Browse files Browse the repository at this point in the history
Update procfs requirement from 0.15.1 to 0.16.0
  • Loading branch information
lambdalisue authored Oct 31, 2023
2 parents f922656 + c93b8a2 commit 35fda1c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rlimit = "0.10.0"

[target.'cfg(target_os = "linux")'.dependencies]
once_cell = "1.13.1"
procfs = { version = "0.15.1", default-features = false }
procfs = { version = "0.16.0", default-features = false }

[target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.51.0"
Expand Down
3 changes: 2 additions & 1 deletion src/collector/linux.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use once_cell::sync::Lazy;
use procfs::prelude::*;
use procfs::process::{LimitValue, Process};

use super::Metrics;
Expand All @@ -15,7 +16,7 @@ pub fn collect() -> Metrics {
Some(bts + ((stat.starttime as f64) / *TICKS_PER_SECOND) as u64);
}
metrics.cpu_seconds_total = Some((stat.utime + stat.stime) as f64 / *TICKS_PER_SECOND);
metrics.resident_memory_bytes = Some(stat.rss_bytes());
metrics.resident_memory_bytes = Some(stat.rss_bytes().get());
metrics.virtual_memory_bytes = Some(stat.vsize);
metrics.threads = Some(stat.num_threads as u64);
}
Expand Down
10 changes: 7 additions & 3 deletions src/collector/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ pub fn collect() -> Metrics {
metrics.cpu_seconds_total = cpu_seconds_total;

let (virtual_memory_bytes, resident_memory_bytes) = {
let memcounters = &PROCESS_MEMORY_COUNTERS_EX::default();
let memcounters = memcounters as *const _ as *mut PROCESS_MEMORY_COUNTERS;
let memcounters = &mut *memcounters;
// We need to use PROCESS_MEMORY_COUNTERS_EX but GetProcessMemoryInfoEx is not provided
// thus we need to cast PROCESS_MEMORY_COUNTERS_EX into PROCESS_MEMORY_COUNTERS to use
// it with GetProcessMemoryInfo.
let memcounters = {
let m = &PROCESS_MEMORY_COUNTERS_EX::default();
m as *const _ as *mut PROCESS_MEMORY_COUNTERS
};
let cb = size_of::<PROCESS_MEMORY_COUNTERS_EX>();
let ret = GetProcessMemoryInfo(h, memcounters, cb as u32);
if ret.is_ok() {
Expand Down

0 comments on commit 35fda1c

Please sign in to comment.