aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_prof/src/lib.rs')
-rw-r--r--crates/ra_prof/src/lib.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index e681b8e0b..6ec24d86d 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -225,6 +225,36 @@ fn print(lvl: usize, msgs: &[Message], out: &mut impl Write, longer_than: Durati
225 } 225 }
226} 226}
227 227
228/// Prints backtrace to stderr, useful for debugging.
229pub fn print_backtrace() {
230 let bt = backtrace::Backtrace::new();
231 eprintln!("{:?}", bt);
232}
233
234thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
235
236/// Allows to check if the current code is withing some dynamic scope, can be
237/// useful during debugging to figure out why a function is called.
238pub struct Scope {
239 _hidden: (),
240}
241
242impl Scope {
243 pub fn enter() -> Scope {
244 IN_SCOPE.with(|slot| *slot.borrow_mut() = true);
245 Scope { _hidden: () }
246 }
247 pub fn is_active() -> bool {
248 IN_SCOPE.with(|slot| *slot.borrow())
249 }
250}
251
252impl Drop for Scope {
253 fn drop(&mut self) {
254 IN_SCOPE.with(|slot| *slot.borrow_mut() = false);
255 }
256}
257
228#[cfg(test)] 258#[cfg(test)]
229mod tests { 259mod tests {
230 use super::*; 260 use super::*;