diff options
author | Jonas Schievink <[email protected]> | 2021-01-18 18:25:55 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-01-18 18:39:46 +0000 |
commit | 9b5fa1c61a85972da419aa29d61286cb9e268f83 (patch) | |
tree | 29704f0e4140261ed68bb5ea3cf52e7385bfc997 /crates | |
parent | 6764d790ac904533dc7618fd38724a135499f87c (diff) |
Add back jemalloc support
Diffstat (limited to 'crates')
-rw-r--r-- | crates/profile/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/profile/src/memory_usage.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 4 |
4 files changed, 18 insertions, 1 deletions
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" | |||
14 | cfg-if = "1" | 14 | cfg-if = "1" |
15 | libc = "0.2.73" | 15 | libc = "0.2.73" |
16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
17 | jemalloc-ctl = { version = "0.3.3", optional = true } | ||
17 | 18 | ||
18 | [target.'cfg(target_os = "linux")'.dependencies] | 19 | [target.'cfg(target_os = "linux")'.dependencies] |
19 | perf-event = "0.4" | 20 | perf-event = "0.4" |
20 | 21 | ||
21 | [features] | 22 | [features] |
22 | cpu_profiler = [] | 23 | cpu_profiler = [] |
24 | jemalloc = ["jemalloc-ctl"] | ||
23 | 25 | ||
24 | # Uncomment to enable for the whole crate graph | 26 | # Uncomment to enable for the whole crate graph |
25 | # default = [ "cpu_profiler" ] | 27 | # 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 { | |||
24 | impl MemoryUsage { | 24 | impl MemoryUsage { |
25 | pub fn current() -> MemoryUsage { | 25 | pub fn current() -> MemoryUsage { |
26 | cfg_if! { | 26 | cfg_if! { |
27 | if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | 27 | if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { |
28 | jemalloc_ctl::epoch::advance().unwrap(); | ||
29 | MemoryUsage { | ||
30 | allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize), | ||
31 | } | ||
32 | } else if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | ||
28 | // Note: This is incredibly slow. | 33 | // Note: This is incredibly slow. |
29 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; | 34 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; |
30 | MemoryUsage { allocated: Bytes(alloc) } | 35 | 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" } | |||
61 | [target.'cfg(windows)'.dependencies] | 61 | [target.'cfg(windows)'.dependencies] |
62 | winapi = "0.3.8" | 62 | winapi = "0.3.8" |
63 | 63 | ||
64 | [target.'cfg(not(target_env = "msvc"))'.dependencies] | ||
65 | jemallocator = { version = "0.3.2", optional = true } | ||
66 | |||
64 | [dev-dependencies] | 67 | [dev-dependencies] |
65 | expect-test = "1.1" | 68 | expect-test = "1.1" |
66 | test_utils = { path = "../test_utils" } | 69 | test_utils = { path = "../test_utils" } |
67 | mbe = { path = "../mbe" } | 70 | mbe = { path = "../mbe" } |
68 | tt = { path = "../tt" } | 71 | tt = { path = "../tt" } |
72 | |||
73 | [features] | ||
74 | 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; | |||
15 | #[global_allocator] | 15 | #[global_allocator] |
16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; | 16 | static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; |
17 | 17 | ||
18 | #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] | ||
19 | #[global_allocator] | ||
20 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
21 | |||
18 | fn main() { | 22 | fn main() { |
19 | if let Err(err) = try_main() { | 23 | if let Err(err) = try_main() { |
20 | eprintln!("{}", err); | 24 | eprintln!("{}", err); |