Skip to content

Commit 2e73ba1

Browse files
bors[bot]Jonas Schievink
andauthored
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]>
2 parents 8b98eaa + 56c090d commit 2e73ba1

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_prof/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ ra_arena = { path = "../ra_arena" }
1414
once_cell = "1.3.1"
1515
backtrace = { version = "0.3.44", optional = true }
1616
mimalloc = { version = "0.1.19", default-features = false, optional = true }
17+
cfg-if = "0.1.10"
18+
libc = "0.2.73"
1719

1820
[target.'cfg(not(target_env = "msvc"))'.dependencies]
1921
jemallocator = { version = "0.3.2", optional = true }

crates/ra_prof/src/memory_usage.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! FIXME: write short doc here
22
3+
use cfg_if::cfg_if;
34
use std::fmt;
45

56
pub struct MemoryUsage {
@@ -8,19 +9,23 @@ pub struct MemoryUsage {
89
}
910

1011
impl MemoryUsage {
11-
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
1212
pub fn current() -> MemoryUsage {
13-
jemalloc_ctl::epoch::advance().unwrap();
14-
MemoryUsage {
15-
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()),
16-
resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()),
13+
cfg_if! {
14+
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
15+
jemalloc_ctl::epoch::advance().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+
}
1727
}
1828
}
19-
20-
#[cfg(any(not(feature = "jemalloc"), target_env = "msvc"))]
21-
pub fn current() -> MemoryUsage {
22-
MemoryUsage { allocated: Bytes(0), resident: Bytes(0) }
23-
}
2429
}
2530

2631
impl fmt::Display for MemoryUsage {

0 commit comments

Comments
 (0)