diff options
Diffstat (limited to 'crates/profile')
-rw-r--r-- | crates/profile/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/profile/src/hprof.rs | 4 | ||||
-rw-r--r-- | crates/profile/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/profile/src/memory_usage.rs | 7 |
4 files changed, 19 insertions, 2 deletions
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index 9c7ce26be..cc7da27f7 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml | |||
@@ -14,12 +14,15 @@ once_cell = "1.3.1" | |||
14 | cfg-if = "1" | 14 | cfg-if = "1" |
15 | libc = "0.2.73" | 15 | libc = "0.2.73" |
16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } | 16 | la-arena = { version = "0.2.0", path = "../../lib/arena" } |
17 | countme = { version = "2.0.0-pre.2", features = ["enable"] } | ||
18 | jemalloc-ctl = { version = "0.3.3", optional = true } | ||
17 | 19 | ||
18 | [target.'cfg(target_os = "linux")'.dependencies] | 20 | [target.'cfg(target_os = "linux")'.dependencies] |
19 | perf-event = "0.4" | 21 | perf-event = "0.4" |
20 | 22 | ||
21 | [features] | 23 | [features] |
22 | cpu_profiler = [] | 24 | cpu_profiler = [] |
25 | jemalloc = ["jemalloc-ctl"] | ||
23 | 26 | ||
24 | # Uncomment to enable for the whole crate graph | 27 | # Uncomment to enable for the whole crate graph |
25 | # default = [ "cpu_profiler" ] | 28 | # default = [ "cpu_profiler" ] |
diff --git a/crates/profile/src/hprof.rs b/crates/profile/src/hprof.rs index 8957ea016..29d2ed518 100644 --- a/crates/profile/src/hprof.rs +++ b/crates/profile/src/hprof.rs | |||
@@ -3,6 +3,7 @@ use once_cell::sync::Lazy; | |||
3 | use std::{ | 3 | use std::{ |
4 | cell::RefCell, | 4 | cell::RefCell, |
5 | collections::{BTreeMap, HashSet}, | 5 | collections::{BTreeMap, HashSet}, |
6 | env, | ||
6 | io::{stderr, Write}, | 7 | io::{stderr, Write}, |
7 | sync::{ | 8 | sync::{ |
8 | atomic::{AtomicBool, Ordering}, | 9 | atomic::{AtomicBool, Ordering}, |
@@ -18,7 +19,8 @@ use crate::tree::{Idx, Tree}; | |||
18 | /// env RA_PROFILE=foo|bar|baz // enabled only selected entries | 19 | /// env RA_PROFILE=foo|bar|baz // enabled only selected entries |
19 | /// env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms | 20 | /// env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms |
20 | pub fn init() { | 21 | pub fn init() { |
21 | let spec = std::env::var("RA_PROFILE").unwrap_or_default(); | 22 | countme::enable(env::var("RA_COUNT").is_ok()); |
23 | let spec = env::var("RA_PROFILE").unwrap_or_default(); | ||
22 | init_from(&spec); | 24 | init_from(&spec); |
23 | } | 25 | } |
24 | 26 | ||
diff --git a/crates/profile/src/lib.rs b/crates/profile/src/lib.rs index aa6ccc36c..79dba47d5 100644 --- a/crates/profile/src/lib.rs +++ b/crates/profile/src/lib.rs | |||
@@ -15,6 +15,13 @@ pub use crate::{ | |||
15 | stop_watch::{StopWatch, StopWatchSpan}, | 15 | stop_watch::{StopWatch, StopWatchSpan}, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub use countme; | ||
19 | /// Include `_c: Count<Self>` field in important structs to count them. | ||
20 | /// | ||
21 | /// To view the counts, run with `RA_COUNT=1`. The overhead of disabled count is | ||
22 | /// almost zero. | ||
23 | pub use countme::Count; | ||
24 | |||
18 | thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false)); | 25 | thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false)); |
19 | 26 | ||
20 | /// Allows to check if the current code is withing some dynamic scope, can be | 27 | /// Allows to check if the current code is withing some dynamic scope, can be |
diff --git a/crates/profile/src/memory_usage.rs b/crates/profile/src/memory_usage.rs index 83390212a..cb4e54447 100644 --- a/crates/profile/src/memory_usage.rs +++ b/crates/profile/src/memory_usage.rs | |||
@@ -24,7 +24,12 @@ impl std::ops::Sub for MemoryUsage { | |||
24 | impl MemoryUsage { | 24 | impl MemoryUsage { |
25 | pub fn current() -> MemoryUsage { | 25 | pub fn current() -> MemoryUsage { |
26 | cfg_if! { | 26 | cfg_if! { |
27 | if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | 27 | if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] { |
28 | jemalloc_ctl::epoch::advance().unwrap(); | ||
29 | MemoryUsage { | ||
30 | allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap() as isize), | ||
31 | } | ||
32 | } else if #[cfg(all(target_os = "linux", target_env = "gnu"))] { | ||
28 | // Note: This is incredibly slow. | 33 | // Note: This is incredibly slow. |
29 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; | 34 | let alloc = unsafe { libc::mallinfo() }.uordblks as isize; |
30 | MemoryUsage { allocated: Bytes(alloc) } | 35 | MemoryUsage { allocated: Bytes(alloc) } |