aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_prof/src/lib.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index 999cc61f0..1fac0b14a 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -27,8 +27,12 @@ pub fn set_filter(f: Filter) {
27 PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); 27 PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst);
28 let set = HashSet::from_iter(f.allowed.iter().cloned()); 28 let set = HashSet::from_iter(f.allowed.iter().cloned());
29 let mut old = FILTER.write().unwrap(); 29 let mut old = FILTER.write().unwrap();
30 let filter_data = 30 let filter_data = FilterData {
31 FilterData { depth: f.depth, allowed: set, cutoff: f.cutoff, version: old.version + 1 }; 31 depth: f.depth,
32 allowed: set,
33 longer_than: f.longer_than,
34 version: old.version + 1,
35 };
32 *old = filter_data; 36 *old = filter_data;
33} 37}
34 38
@@ -102,7 +106,7 @@ pub struct Profiler {
102pub struct Filter { 106pub struct Filter {
103 depth: usize, 107 depth: usize,
104 allowed: Vec<String>, 108 allowed: Vec<String>,
105 cutoff: Duration, 109 longer_than: Duration,
106} 110}
107 111
108impl Filter { 112impl Filter {
@@ -111,10 +115,10 @@ impl Filter {
111 // env RA_PROFILE=foo|bar|baz // enabled only selected entries 115 // env RA_PROFILE=foo|bar|baz // enabled only selected entries
112 // env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms 116 // env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms
113 pub fn from_spec(mut spec: &str) -> Filter { 117 pub fn from_spec(mut spec: &str) -> Filter {
114 let cutoff = if let Some(idx) = spec.rfind(">") { 118 let longer_than = if let Some(idx) = spec.rfind(">") {
115 let cutoff = spec[idx + 1..].parse().expect("invalid profile cutoff"); 119 let longer_than = spec[idx + 1..].parse().expect("invalid profile longer_than");
116 spec = &spec[..idx]; 120 spec = &spec[..idx];
117 Duration::from_millis(cutoff) 121 Duration::from_millis(longer_than)
118 } else { 122 } else {
119 Duration::new(0, 0) 123 Duration::new(0, 0)
120 }; 124 };
@@ -128,15 +132,15 @@ impl Filter {
128 }; 132 };
129 let allowed = 133 let allowed =
130 if spec == "*" { Vec::new() } else { spec.split("|").map(String::from).collect() }; 134 if spec == "*" { Vec::new() } else { spec.split("|").map(String::from).collect() };
131 Filter::new(depth, allowed, cutoff) 135 Filter::new(depth, allowed, longer_than)
132 } 136 }
133 137
134 pub fn disabled() -> Filter { 138 pub fn disabled() -> Filter {
135 Filter::new(0, Vec::new(), Duration::new(0, 0)) 139 Filter::new(0, Vec::new(), Duration::new(0, 0))
136 } 140 }
137 141
138 pub fn new(depth: usize, allowed: Vec<String>, cutoff: Duration) -> Filter { 142 pub fn new(depth: usize, allowed: Vec<String>, longer_than: Duration) -> Filter {
139 Filter { depth, allowed, cutoff } 143 Filter { depth, allowed, longer_than }
140 } 144 }
141} 145}
142 146
@@ -163,7 +167,7 @@ struct FilterData {
163 depth: usize, 167 depth: usize,
164 version: usize, 168 version: usize,
165 allowed: HashSet<String>, 169 allowed: HashSet<String>,
166 cutoff: Duration, 170 longer_than: Duration,
167} 171}
168 172
169static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false); 173static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false);
@@ -187,7 +191,7 @@ impl Drop for Profiler {
187 stack.messages.push(Message { level, duration, message }); 191 stack.messages.push(Message { level, duration, message });
188 if level == 0 { 192 if level == 0 {
189 let stdout = stderr(); 193 let stdout = stderr();
190 if duration >= stack.filter_data.cutoff { 194 if duration >= stack.filter_data.longer_than {
191 print(0, &stack.messages, &mut stdout.lock()); 195 print(0, &stack.messages, &mut stdout.lock());
192 } 196 }
193 stack.messages.clear(); 197 stack.messages.clear();