aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-03 22:25:43 +0100
committerAleksey Kladov <[email protected]>2019-06-03 22:27:49 +0100
commit5264711b5d385fbdd6f58f19190c454bee733ece (patch)
tree3ebfd66123704068d95558bcc5fb3757385f7f14 /crates/ra_prof/src
parent6aa8d8b99da1641f1cbec6c767187dfdb7cee0dc (diff)
add couple of debug utils
Diffstat (limited to 'crates/ra_prof/src')
-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::*;