diff options
author | Aleksey Kladov <[email protected]> | 2020-04-25 18:50:42 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-25 18:50:42 +0100 |
commit | 95b989ec3059eca140d9bfffee1bc52e30f9d17b (patch) | |
tree | 4d3872fa4b9987041627e31fd15c459bd3355402 | |
parent | 726938f598378f6d88b6b5ee91e1cea8f323029d (diff) |
Simplify
-rw-r--r-- | crates/ra_prof/src/hprof.rs | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/crates/ra_prof/src/hprof.rs b/crates/ra_prof/src/hprof.rs index 6d91206ae..4bbe5cb12 100644 --- a/crates/ra_prof/src/hprof.rs +++ b/crates/ra_prof/src/hprof.rs | |||
@@ -77,6 +77,19 @@ impl Profiler { | |||
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | impl Drop for Profiler { | ||
81 | fn drop(&mut self) { | ||
82 | match self { | ||
83 | Profiler { label: Some(label), detail } => { | ||
84 | PROFILE_STACK.with(|stack| { | ||
85 | stack.borrow_mut().pop(label, detail.take()); | ||
86 | }); | ||
87 | } | ||
88 | Profiler { label: None, .. } => (), | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
80 | static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false); | 93 | static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false); |
81 | static FILTER: Lazy<RwLock<Filter>> = Lazy::new(Default::default); | 94 | static FILTER: Lazy<RwLock<Filter>> = Lazy::new(Default::default); |
82 | thread_local!(static PROFILE_STACK: RefCell<ProfileStack> = RefCell::new(ProfileStack::new())); | 95 | thread_local!(static PROFILE_STACK: RefCell<ProfileStack> = RefCell::new(ProfileStack::new())); |
@@ -90,10 +103,6 @@ struct Filter { | |||
90 | } | 103 | } |
91 | 104 | ||
92 | impl Filter { | 105 | impl Filter { |
93 | fn new(depth: usize, allowed: HashSet<String>, longer_than: Duration) -> Filter { | ||
94 | Filter { depth, allowed, longer_than, version: 0 } | ||
95 | } | ||
96 | |||
97 | fn disabled() -> Filter { | 106 | fn disabled() -> Filter { |
98 | Filter::default() | 107 | Filter::default() |
99 | } | 108 | } |
@@ -116,7 +125,7 @@ impl Filter { | |||
116 | }; | 125 | }; |
117 | let allowed = | 126 | let allowed = |
118 | if spec == "*" { HashSet::new() } else { spec.split('|').map(String::from).collect() }; | 127 | if spec == "*" { HashSet::new() } else { spec.split('|').map(String::from).collect() }; |
119 | Filter::new(depth, allowed, longer_than) | 128 | Filter { depth, allowed, longer_than, version: 0 } |
120 | } | 129 | } |
121 | 130 | ||
122 | fn install(mut self) { | 131 | fn install(mut self) { |
@@ -171,28 +180,16 @@ impl ProfileStack { | |||
171 | let level = self.starts.len(); | 180 | let level = self.starts.len(); |
172 | self.messages.push(Message { level, duration, label, detail }); | 181 | self.messages.push(Message { level, duration, label, detail }); |
173 | if level == 0 { | 182 | if level == 0 { |
174 | let stdout = stderr(); | ||
175 | let longer_than = self.filter.longer_than; | 183 | let longer_than = self.filter.longer_than; |
176 | // Convert to millis for comparison to avoid problems with rounding | 184 | // Convert to millis for comparison to avoid problems with rounding |
177 | // (otherwise we could print `0ms` despite user's `>0` filter when | 185 | // (otherwise we could print `0ms` despite user's `>0` filter when |
178 | // `duration` is just a few nanos). | 186 | // `duration` is just a few nanos). |
179 | if duration.as_millis() > longer_than.as_millis() { | 187 | if duration.as_millis() > longer_than.as_millis() { |
180 | print(&self.messages, longer_than, &mut stdout.lock()); | 188 | let stderr = stderr(); |
189 | print(&self.messages, longer_than, &mut stderr.lock()); | ||
181 | } | 190 | } |
182 | self.messages.clear(); | 191 | self.messages.clear(); |
183 | } | 192 | assert!(self.starts.is_empty()) |
184 | } | ||
185 | } | ||
186 | |||
187 | impl Drop for Profiler { | ||
188 | fn drop(&mut self) { | ||
189 | match self { | ||
190 | Profiler { label: Some(label), detail } => { | ||
191 | PROFILE_STACK.with(|stack| { | ||
192 | stack.borrow_mut().pop(label, detail.take()); | ||
193 | }); | ||
194 | } | ||
195 | Profiler { label: None, .. } => (), | ||
196 | } | 193 | } |
197 | } | 194 | } |
198 | } | 195 | } |