mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Allow gathering memory stats on non-jemalloc Linux
This commit is contained in:
parent
a3ff2751b4
commit
56c090d0d0
3 changed files with 19 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1198,8 +1198,10 @@ name = "ra_prof"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
|
"cfg-if",
|
||||||
"jemalloc-ctl",
|
"jemalloc-ctl",
|
||||||
"jemallocator",
|
"jemallocator",
|
||||||
|
"libc",
|
||||||
"mimalloc",
|
"mimalloc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"ra_arena",
|
"ra_arena",
|
||||||
|
|
|
@ -14,6 +14,8 @@ ra_arena = { path = "../ra_arena" }
|
||||||
once_cell = "1.3.1"
|
once_cell = "1.3.1"
|
||||||
backtrace = { version = "0.3.44", optional = true }
|
backtrace = { version = "0.3.44", optional = true }
|
||||||
mimalloc = { version = "0.1.19", default-features = false, optional = true }
|
mimalloc = { version = "0.1.19", default-features = false, optional = true }
|
||||||
|
cfg-if = "0.1.10"
|
||||||
|
libc = "0.2.73"
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
jemallocator = { version = "0.3.2", optional = true }
|
jemallocator = { version = "0.3.2", optional = true }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub struct MemoryUsage {
|
pub struct MemoryUsage {
|
||||||
|
@ -8,19 +9,23 @@ pub struct MemoryUsage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryUsage {
|
impl MemoryUsage {
|
||||||
#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
|
|
||||||
pub fn current() -> MemoryUsage {
|
pub fn current() -> MemoryUsage {
|
||||||
jemalloc_ctl::epoch::advance().unwrap();
|
cfg_if! {
|
||||||
MemoryUsage {
|
if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
|
||||||
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()),
|
jemalloc_ctl::epoch::advance().unwrap();
|
||||||
resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()),
|
MemoryUsage {
|
||||||
|
allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()),
|
||||||
|
resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()),
|
||||||
|
}
|
||||||
|
} else if #[cfg(target_os = "linux")] {
|
||||||
|
// Note: This is incredibly slow.
|
||||||
|
let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize;
|
||||||
|
MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) }
|
||||||
|
} else {
|
||||||
|
MemoryUsage { allocated: Bytes(0), resident: Bytes(0) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(not(feature = "jemalloc"), target_env = "msvc"))]
|
|
||||||
pub fn current() -> MemoryUsage {
|
|
||||||
MemoryUsage { allocated: Bytes(0), resident: Bytes(0) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for MemoryUsage {
|
impl fmt::Display for MemoryUsage {
|
||||||
|
|
Loading…
Reference in a new issue