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 ++++++- crates/rust-analyzer/Cargo.toml | 6 ++++++ crates/rust-analyzer/src/bin/main.rs | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'crates') 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) } diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index af7b86ead..3cb45b030 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -61,8 +61,14 @@ proc_macro_srv = { path = "../proc_macro_srv", version = "0.0.0" } [target.'cfg(windows)'.dependencies] winapi = "0.3.8" +[target.'cfg(not(target_env = "msvc"))'.dependencies] +jemallocator = { version = "0.3.2", optional = true } + [dev-dependencies] expect-test = "1.1" test_utils = { path = "../test_utils" } mbe = { path = "../mbe" } tt = { path = "../tt" } + +[features] +jemalloc = ["jemallocator", "profile/jemalloc"] diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index bf42654a8..2f7f94a39 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -15,6 +15,10 @@ use vfs::AbsPathBuf; #[global_allocator] static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; +#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + fn main() { if let Err(err) = try_main() { eprintln!("{}", err); -- cgit v1.2.3