aboutsummaryrefslogtreecommitdiff
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
parent6aa8d8b99da1641f1cbec6c767187dfdb7cee0dc (diff)
parent5264711b5d385fbdd6f58f19190c454bee733ece (diff)
Merge #1373
1373: add couple of debug utils r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock9
-rw-r--r--crates/ra_prof/Cargo.toml1
-rw-r--r--crates/ra_prof/src/lib.rs30
3 files changed, 36 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e38fa0ff0..4dbe5679d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -41,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41 41
42[[package]] 42[[package]]
43name = "backtrace" 43name = "backtrace"
44version = "0.3.26" 44version = "0.3.28"
45source = "registry+https://github.com/rust-lang/crates.io-index" 45source = "registry+https://github.com/rust-lang/crates.io-index"
46dependencies = [ 46dependencies = [
47 "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 47 "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -381,7 +381,7 @@ name = "error-chain"
381version = "0.12.1" 381version = "0.12.1"
382source = "registry+https://github.com/rust-lang/crates.io-index" 382source = "registry+https://github.com/rust-lang/crates.io-index"
383dependencies = [ 383dependencies = [
384 "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", 384 "backtrace 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
385 "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 385 "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
386] 386]
387 387
@@ -390,7 +390,7 @@ name = "failure"
390version = "0.1.5" 390version = "0.1.5"
391source = "registry+https://github.com/rust-lang/crates.io-index" 391source = "registry+https://github.com/rust-lang/crates.io-index"
392dependencies = [ 392dependencies = [
393 "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", 393 "backtrace 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
394 "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 394 "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
395] 395]
396 396
@@ -1179,6 +1179,7 @@ dependencies = [
1179name = "ra_prof" 1179name = "ra_prof"
1180version = "0.1.0" 1180version = "0.1.0"
1181dependencies = [ 1181dependencies = [
1182 "backtrace 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
1182 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 1183 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
1183 "once_cell 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 1184 "once_cell 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
1184] 1185]
@@ -1986,7 +1987,7 @@ dependencies = [
1986"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" 1987"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
1987"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" 1988"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
1988"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" 1989"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
1989"checksum backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)" = "1a13fc43f04daf08ab4f71e3d27e1fc27fc437d3e95ac0063a796d92fb40f39b" 1990"checksum backtrace 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c18049b371fef38d66b2d69643618023d9d6b4e62891019f3359e88f73922a"
1990"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" 1991"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
1991"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" 1992"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
1992"checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" 1993"checksum bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80"
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::*;