From 9b5fa1c61a85972da419aa29d61286cb9e268f83 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 18 Jan 2021 19:25:55 +0100 Subject: Add back jemalloc support --- crates/profile/Cargo.toml | 2 ++ crates/profile/src/memory_usage.rs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'crates/profile') diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index 9c7ce26be..f7231c2b8 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml @@ -14,12 +14,14 @@ once_cell = "1.3.1" cfg-if = "1" libc = "0.2.73" la-arena = { version = "0.2.0", path = "../../lib/arena" } +jemalloc-ctl = { version = "0.3.3", optional = true } [target.'cfg(target_os = "linux")'.dependencies] perf-event = "0.4" [features] cpu_profiler = [] +jemalloc = ["jemalloc-ctl"] # Uncomment to enable for the whole crate graph # default = [ "cpu_profiler" ] diff --git a/crates/profile/src/memory_usage.rs b/crates/profile/src/memory_usage.rs index 83390212a..cb4e54447 100644 --- a/crates/profile/src/memory_usage.rs +++ b/crates/profile/src/memory_usage.rs @@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage { impl MemoryUsage { pub fn current() -> MemoryUsage { cfg_if! { - if #[cfg(all(target_os = "linux", target_env = "gnu"))] { + if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { + jemalloc_ctl::epoch::advance().unwrap(); + MemoryUsage { + allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize), + } + } else if #[cfg(all(target_os = "linux", target_env = "gnu"))] { // Note: This is incredibly slow. let alloc = unsafe { libc::mallinfo() }.uordblks as isize; MemoryUsage { allocated: Bytes(alloc) } -- cgit v1.2.3