From f3c34d5b8c6b227da3694eb2e587144d29d7af06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 7 Feb 2024 10:09:39 +0100 Subject: [PATCH] Simplify MemoryStats fetching --- tracing-trace/src/entry.rs | 5 +++++ tracing-trace/src/layer.rs | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tracing-trace/src/entry.rs b/tracing-trace/src/entry.rs index 29cf9326c..26e543ba0 100644 --- a/tracing-trace/src/entry.rs +++ b/tracing-trace/src/entry.rs @@ -121,6 +121,11 @@ impl MemoryStats { } } + #[cfg(not(any(target_os = "linux", target_os = "macos")))] + pub fn fetch() -> Option { + None + } + pub fn checked_sub(self, other: Self) -> Option { Some(Self { resident: self.resident.checked_sub(other.resident)? }) } diff --git a/tracing-trace/src/layer.rs b/tracing-trace/src/layer.rs index a2d3232c8..b30e1ad38 100644 --- a/tracing-trace/src/layer.rs +++ b/tracing-trace/src/layer.rs @@ -96,14 +96,8 @@ impl TraceLayer { self.start_time.elapsed() } - #[cfg(any(target_os = "linux", target_os = "macos"))] fn memory_stats(&self) -> Option { - Some(MemoryStats::fetch().unwrap()) - } - - #[cfg(not(any(target_os = "linux", target_os = "macos")))] - fn memory_stats(&self) -> Option { - None + MemoryStats::fetch() } fn send(&self, entry: Entry) {