aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-03 22:28:16 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-03 22:28:16 +0100
commitd1b9fa446a3dbfb216fcc0b07d8a2990c632df9c (patch)
tree3ebfd66123704068d95558bcc5fb3757385f7f14 /crates
parent6aa8d8b99da1641f1cbec6c767187dfdb7cee0dc (diff)
parent5264711b5d385fbdd6f58f19190c454bee733ece (diff)
Merge #1373
1373: add couple of debug utils r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_prof/Cargo.toml1
-rw-r--r--crates/ra_prof/src/lib.rs30
2 files changed, 31 insertions, 0 deletions
diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml
index efcce3d65..d55af18f5 100644
--- a/crates/ra_prof/Cargo.toml
+++ b/crates/ra_prof/Cargo.toml
@@ -8,3 +8,4 @@ publish = false
8[dependencies] 8[dependencies]
9once_cell = "0.2.0" 9once_cell = "0.2.0"
10itertools = "0.8.0" 10itertools = "0.8.0"
11backtrace = "0.3.28"
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::*;