aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_prof')
-rw-r--r--crates/ra_prof/Cargo.toml10
-rw-r--r--crates/ra_prof/src/lib.rs10
-rw-r--r--crates/ra_prof/src/memory_usage.rs21
3 files changed, 12 insertions, 29 deletions
diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml
index b3d52985a..6c214501e 100644
--- a/crates/ra_prof/Cargo.toml
+++ b/crates/ra_prof/Cargo.toml
@@ -13,18 +13,12 @@ doctest = false
13ra_arena = { path = "../ra_arena" } 13ra_arena = { path = "../ra_arena" }
14once_cell = "1.3.1" 14once_cell = "1.3.1"
15backtrace = { version = "0.3.44", optional = true } 15backtrace = { version = "0.3.44", optional = true }
16mimalloc = { version = "0.1.19", default-features = false, optional = true } 16cfg-if = "0.1.10"
17 17libc = "0.2.73"
18[target.'cfg(not(target_env = "msvc"))'.dependencies]
19jemallocator = { version = "0.3.2", optional = true }
20jemalloc-ctl = { version = "0.3.3", optional = true }
21 18
22[features] 19[features]
23jemalloc = [ "jemallocator", "jemalloc-ctl" ]
24cpu_profiler = [] 20cpu_profiler = []
25 21
26# Uncomment to enable for the whole crate graph 22# Uncomment to enable for the whole crate graph
27# default = [ "backtrace" ] 23# default = [ "backtrace" ]
28# default = [ "jemalloc" ]
29# default = [ "mimalloc" ]
30# default = [ "cpu_profiler" ] 24# default = [ "cpu_profiler" ]
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index b54531b4e..ba5609703 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -13,16 +13,6 @@ pub use crate::{
13 memory_usage::{Bytes, MemoryUsage}, 13 memory_usage::{Bytes, MemoryUsage},
14}; 14};
15 15
16// We use jemalloc mainly to get heap usage statistics, actual performance
17// difference is not measures.
18#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
19#[global_allocator]
20static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
21
22#[cfg(all(feature = "mimalloc"))]
23#[global_allocator]
24static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
25
26/// Prints backtrace to stderr, useful for debugging. 16/// Prints backtrace to stderr, useful for debugging.
27#[cfg(feature = "backtrace")] 17#[cfg(feature = "backtrace")]
28pub fn print_backtrace() { 18pub fn print_backtrace() {
diff --git a/crates/ra_prof/src/memory_usage.rs b/crates/ra_prof/src/memory_usage.rs
index 9768f656c..ee79ec3ee 100644
--- a/crates/ra_prof/src/memory_usage.rs
+++ b/crates/ra_prof/src/memory_usage.rs
@@ -1,26 +1,25 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2
3use std::fmt; 2use std::fmt;
4 3
4use cfg_if::cfg_if;
5
5pub struct MemoryUsage { 6pub struct MemoryUsage {
6 pub allocated: Bytes, 7 pub allocated: Bytes,
7 pub resident: Bytes, 8 pub resident: Bytes,
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(target_os = "linux")] {
15 allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()), 15 // Note: This is incredibly slow.
16 resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()), 16 let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize;
17 MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) }
18 } else {
19 MemoryUsage { allocated: Bytes(0), resident: Bytes(0) }
20 }
17 } 21 }
18 } 22 }
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} 23}
25 24
26impl fmt::Display for MemoryUsage { 25impl fmt::Display for MemoryUsage {