diff options
-rw-r--r-- | crates/ra_prof/src/lib.rs | 25 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 6 |
2 files changed, 15 insertions, 16 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 2d4f68f5e..d95ad3107 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -26,11 +26,18 @@ pub use crate::memory_usage::{Bytes, MemoryUsage}; | |||
26 | #[global_allocator] | 26 | #[global_allocator] |
27 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | 27 | static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; |
28 | 28 | ||
29 | /// Filtering syntax | ||
30 | /// env RA_PROFILE=* // dump everything | ||
31 | /// env RA_PROFILE=foo|bar|baz // enabled only selected entries | ||
32 | /// env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms | ||
29 | pub fn init() { | 33 | pub fn init() { |
30 | set_filter(match std::env::var("RA_PROFILE") { | 34 | let spec = std::env::var("RA_PROFILE").unwrap_or_default(); |
31 | Ok(spec) => Filter::from_spec(&spec), | 35 | init_from(&spec); |
32 | Err(_) => Filter::disabled(), | 36 | } |
33 | }); | 37 | |
38 | pub fn init_from(spec: &str) { | ||
39 | let filter = if spec.is_empty() { Filter::disabled() } else { Filter::from_spec(spec) }; | ||
40 | set_filter(filter); | ||
34 | } | 41 | } |
35 | 42 | ||
36 | /// Set profiling filter. It specifies descriptions allowed to profile. | 43 | /// Set profiling filter. It specifies descriptions allowed to profile. |
@@ -43,7 +50,7 @@ pub fn init() { | |||
43 | /// let f = Filter::from_spec("profile1|profile2@2"); | 50 | /// let f = Filter::from_spec("profile1|profile2@2"); |
44 | /// set_filter(f); | 51 | /// set_filter(f); |
45 | /// ``` | 52 | /// ``` |
46 | pub fn set_filter(f: Filter) { | 53 | fn set_filter(f: Filter) { |
47 | PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); | 54 | PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); |
48 | let set: HashSet<_> = f.allowed.iter().cloned().collect(); | 55 | let set: HashSet<_> = f.allowed.iter().cloned().collect(); |
49 | let mut old = FILTER.write().unwrap(); | 56 | let mut old = FILTER.write().unwrap(); |
@@ -127,18 +134,14 @@ impl Profiler { | |||
127 | } | 134 | } |
128 | } | 135 | } |
129 | 136 | ||
130 | pub struct Filter { | 137 | struct Filter { |
131 | depth: usize, | 138 | depth: usize, |
132 | allowed: Vec<String>, | 139 | allowed: Vec<String>, |
133 | longer_than: Duration, | 140 | longer_than: Duration, |
134 | } | 141 | } |
135 | 142 | ||
136 | impl Filter { | 143 | impl Filter { |
137 | // Filtering syntax | 144 | fn from_spec(mut spec: &str) -> Filter { |
138 | // env RA_PROFILE=* // dump everything | ||
139 | // env RA_PROFILE=foo|bar|baz // enabled only selected entries | ||
140 | // env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms | ||
141 | pub fn from_spec(mut spec: &str) -> Filter { | ||
142 | let longer_than = if let Some(idx) = spec.rfind('>') { | 145 | let longer_than = if let Some(idx) = spec.rfind('>') { |
143 | let longer_than = spec[idx + 1..].parse().expect("invalid profile longer_than"); | 146 | let longer_than = spec[idx + 1..].parse().expect("invalid profile longer_than"); |
144 | spec = &spec[..idx]; | 147 | spec = &spec[..idx]; |
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 7eebedff7..e4fe3411a 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -62,11 +62,7 @@ impl<'a> Project<'a> { | |||
62 | static INIT: Once = Once::new(); | 62 | static INIT: Once = Once::new(); |
63 | INIT.call_once(|| { | 63 | INIT.call_once(|| { |
64 | env_logger::builder().is_test(true).try_init().unwrap(); | 64 | env_logger::builder().is_test(true).try_init().unwrap(); |
65 | ra_prof::set_filter(if crate::PROFILE.is_empty() { | 65 | ra_prof::init_from(crate::PROFILE); |
66 | ra_prof::Filter::disabled() | ||
67 | } else { | ||
68 | ra_prof::Filter::from_spec(&crate::PROFILE) | ||
69 | }); | ||
70 | }); | 66 | }); |
71 | 67 | ||
72 | let mut paths = vec![]; | 68 | let mut paths = vec![]; |