aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof/src
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-07-21 18:30:17 +0100
committerJonas Schievink <[email protected]>2020-07-21 18:55:54 +0100
commit56c090d0d0ad68c0dd195684e4d8180ea149692f (patch)
tree15bf2a269ff33efb86b4769b799ba9559ce60b66 /crates/ra_prof/src
parenta3ff2751b4cf8625e2874a482fe4d58da3d02891 (diff)
Allow gathering memory stats on non-jemalloc Linux
Diffstat (limited to 'crates/ra_prof/src')
-rw-r--r--crates/ra_prof/src/memory_usage.rs25
1 files changed, 15 insertions, 10 deletions
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
3use cfg_if::cfg_if;
3use std::fmt; 4use std::fmt;
4 5
5pub struct MemoryUsage { 6pub struct MemoryUsage {
@@ -8,19 +9,23 @@ pub struct MemoryUsage {
8} 9}
9 10
10impl MemoryUsage { 11impl 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
26impl fmt::Display for MemoryUsage { 31impl fmt::Display for MemoryUsage {