From 7fe4444b656d636e9ae966e6ec22c17a61ba3b62 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 29 Jul 2022 16:56:45 -0500 Subject: [PATCH] :heavy_plus_sign: linux-only memory measurement --- crates/ptth_relay/src/scraper_api.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ptth_relay/src/scraper_api.rs b/crates/ptth_relay/src/scraper_api.rs index 004118c..3bf6512 100644 --- a/crates/ptth_relay/src/scraper_api.rs +++ b/crates/ptth_relay/src/scraper_api.rs @@ -249,6 +249,20 @@ pub async fn handle ( } } +fn get_rss_from_status (proc_status: &str) -> Option +{ + use std::str::FromStr; + + for line in proc_status.lines () { + if let Some (rest) = line.strip_prefix ("VmRSS:\t").and_then (|s| s.strip_suffix (" kB")) + { + return u64::from_str (rest.trim_start ()).ok (); + } + } + + None +} + #[cfg (test)] mod tests { use std::{ @@ -425,4 +439,11 @@ mod tests { }); } + + #[test] + fn rss () { + let input = "VmHWM: 584 kB\nVmRSS: 584 kB\nRssAnon: 68 kB\n"; + + assert_eq! (get_rss_from_status (input), Some (584)); + } }