aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-25 18:50:42 +0100
committerAleksey Kladov <[email protected]>2020-04-25 18:50:42 +0100
commit95b989ec3059eca140d9bfffee1bc52e30f9d17b (patch)
tree4d3872fa4b9987041627e31fd15c459bd3355402
parent726938f598378f6d88b6b5ee91e1cea8f323029d (diff)
Simplify
-rw-r--r--crates/ra_prof/src/hprof.rs37
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
80impl 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
80static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false); 93static PROFILING_ENABLED: AtomicBool = AtomicBool::new(false);
81static FILTER: Lazy<RwLock<Filter>> = Lazy::new(Default::default); 94static FILTER: Lazy<RwLock<Filter>> = Lazy::new(Default::default);
82thread_local!(static PROFILE_STACK: RefCell<ProfileStack> = RefCell::new(ProfileStack::new())); 95thread_local!(static PROFILE_STACK: RefCell<ProfileStack> = RefCell::new(ProfileStack::new()));
@@ -90,10 +103,6 @@ struct Filter {
90} 103}
91 104
92impl Filter { 105impl 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
187impl 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}