diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-22 12:00:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-22 12:00:17 +0100 |
commit | 2e73ba1b49b70a2cfc6f70659d77ddf3e209448a (patch) | |
tree | e06cb44bd6702343665b6c070bf151c1acfce05d | |
parent | 8b98eaa573f42e346049bb90473b9f821e7fbaf3 (diff) | |
parent | 56c090d0d0ad68c0dd195684e4d8180ea149692f (diff) |
Merge #5479
5479: Allow gathering memory stats on non-jemalloc Linux r=matklad a=jonas-schievink
I could also parse `/proc/$PID/statm` to get the resident set size, but decided against that for now as it isn't terribly useful.
Note that `mallinfo()` is incredibly slow for some reason, and unfortunately this will be exposed to users via the "Memory Usage" command (even worse, the opened document will show the outdated values while the server is processing). So, not very ideal, but it keeps me from recompiling r-a with different feature sets all the time.
Co-authored-by: Jonas Schievink <[email protected]>
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | crates/ra_prof/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_prof/src/memory_usage.rs | 25 |
3 files changed, 19 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock index 604233a59..4a8271f09 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1198,8 +1198,10 @@ name = "ra_prof" | |||
1198 | version = "0.1.0" | 1198 | version = "0.1.0" |
1199 | dependencies = [ | 1199 | dependencies = [ |
1200 | "backtrace", | 1200 | "backtrace", |
1201 | "cfg-if", | ||
1201 | "jemalloc-ctl", | 1202 | "jemalloc-ctl", |
1202 | "jemallocator", | 1203 | "jemallocator", |
1204 | "libc", | ||
1203 | "mimalloc", | 1205 | "mimalloc", |
1204 | "once_cell", | 1206 | "once_cell", |
1205 | "ra_arena", | 1207 | "ra_arena", |
diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml index b3d52985a..2e60858f1 100644 --- a/crates/ra_prof/Cargo.toml +++ b/crates/ra_prof/Cargo.toml | |||
@@ -14,6 +14,8 @@ ra_arena = { path = "../ra_arena" } | |||
14 | once_cell = "1.3.1" | 14 | once_cell = "1.3.1" |
15 | backtrace = { version = "0.3.44", optional = true } | 15 | backtrace = { version = "0.3.44", optional = true } |
16 | mimalloc = { version = "0.1.19", default-features = false, optional = true } | 16 | mimalloc = { version = "0.1.19", default-features = false, optional = true } |
17 | cfg-if = "0.1.10" | ||
18 | libc = "0.2.73" | ||
17 | 19 | ||
18 | [target.'cfg(not(target_env = "msvc"))'.dependencies] | 20 | [target.'cfg(not(target_env = "msvc"))'.dependencies] |
19 | jemallocator = { version = "0.3.2", optional = true } | 21 | jemallocator = { version = "0.3.2", optional = true } |
diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs index 9768f656c..b1858b06f 100644 --- a/crates/ra_prof/src/memory_usage.rs +++ b/crates/ra_prof/src/memory_usage.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use cfg_if::cfg_if; | ||
3 | use std::fmt; | 4 | use std::fmt; |
4 | 5 | ||
5 | pub struct MemoryUsage { | 6 | pub struct MemoryUsage { |
@@ -8,19 +9,23 @@ pub struct MemoryUsage { | |||
8 | } | 9 | } |
9 | 10 | ||
10 | impl MemoryUsage { | 11 | impl MemoryUsage { |
11 | #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] | ||
12 | pub fn current() -> MemoryUsage { | 12 | pub fn current() -> MemoryUsage { |
13 | jemalloc_ctl::epoch::advance().unwrap(); | 13 | cfg_if! { |
14 | MemoryUsage { | 14 | if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { |
15 | allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()), | 15 | jemalloc_ctl::epoch::advance().unwrap(); |
16 | resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()), | 16 | MemoryUsage { |
17 | allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()), | ||
18 | resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()), | ||
19 | } | ||
20 | } else if #[cfg(target_os = "linux")] { | ||
21 | // Note: This is incredibly slow. | ||
22 | let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize; | ||
23 | MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) } | ||
24 | } else { | ||
25 | MemoryUsage { allocated: Bytes(0), resident: Bytes(0) } | ||
26 | } | ||
17 | } | 27 | } |
18 | } | 28 | } |
19 | |||
20 | #[cfg(any(not(feature = "jemalloc"), target_env = "msvc"))] | ||
21 | pub fn current() -> MemoryUsage { | ||
22 | MemoryUsage { allocated: Bytes(0), resident: Bytes(0) } | ||
23 | } | ||
24 | } | 29 | } |
25 | 30 | ||
26 | impl fmt::Display for MemoryUsage { | 31 | impl fmt::Display for MemoryUsage { |