aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-14 11:56:01 +0000
committerGitHub <[email protected]>2021-01-14 11:56:01 +0000
commit022d031b7fe9266ad3dd320c729989e8bf495b67 (patch)
treee8467dbbdcc43f4b119ea8f4485d0738a5a2577d /crates
parent947850c2d9e2fa832516e3486efa0dd9c4d30e73 (diff)
parent865e05b5b47d3e27e8fe4458662e751e492a0f51 (diff)
Merge #7266
7266: Make printin the backtrace more convenient r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/profile/Cargo.toml2
-rw-r--r--crates/profile/src/lib.rs15
-rw-r--r--crates/stdx/Cargo.toml5
-rw-r--r--crates/stdx/src/lib.rs29
4 files changed, 26 insertions, 25 deletions
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml
index c5dfdff32..4951f1835 100644
--- a/crates/profile/Cargo.toml
+++ b/crates/profile/Cargo.toml
@@ -13,7 +13,6 @@ doctest = false
13once_cell = "1.3.1" 13once_cell = "1.3.1"
14cfg-if = "1" 14cfg-if = "1"
15libc = "0.2.73" 15libc = "0.2.73"
16backtrace = { version = "0.3.44", optional = true }
17 16
18arena = { path = "../arena", version = "0.0.0" } 17arena = { path = "../arena", version = "0.0.0" }
19 18
@@ -24,5 +23,4 @@ perf-event = "0.4"
24cpu_profiler = [] 23cpu_profiler = []
25 24
26# Uncomment to enable for the whole crate graph 25# Uncomment to enable for the whole crate graph
27# default = [ "backtrace" ]
28# default = [ "cpu_profiler" ] 26# default = [ "cpu_profiler" ]
diff --git a/crates/profile/src/lib.rs b/crates/profile/src/lib.rs
index ab19271c7..aa6ccc36c 100644
--- a/crates/profile/src/lib.rs
+++ b/crates/profile/src/lib.rs
@@ -15,21 +15,6 @@ pub use crate::{
15 stop_watch::{StopWatch, StopWatchSpan}, 15 stop_watch::{StopWatch, StopWatchSpan},
16}; 16};
17 17
18/// Prints backtrace to stderr, useful for debugging.
19#[cfg(feature = "backtrace")]
20pub fn print_backtrace() {
21 let bt = backtrace::Backtrace::new();
22 eprintln!("{:?}", bt);
23}
24#[cfg(not(feature = "backtrace"))]
25pub fn print_backtrace() {
26 eprintln!(
27 r#"enable the backtrace feature:
28 profile = {{ path = "../profile", features = [ "backtrace"] }}
29"#
30 );
31}
32
33thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false)); 18thread_local!(static IN_SCOPE: RefCell<bool> = RefCell::new(false));
34 19
35/// Allows to check if the current code is withing some dynamic scope, can be 20/// Allows to check if the current code is withing some dynamic scope, can be
diff --git a/crates/stdx/Cargo.toml b/crates/stdx/Cargo.toml
index 8d7a51156..c47e8d0a8 100644
--- a/crates/stdx/Cargo.toml
+++ b/crates/stdx/Cargo.toml
@@ -10,4 +10,9 @@ edition = "2018"
10doctest = false 10doctest = false
11 11
12[dependencies] 12[dependencies]
13backtrace = { version = "0.3.44", optional = true }
13# Think twice before adding anything here 14# Think twice before adding anything here
15
16[features]
17# Uncomment to enable for the whole crate graph
18# default = [ "backtrace" ]
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 13aab1451..d9a62e943 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -25,6 +25,27 @@ pub fn timeit(label: &'static str) -> impl Drop {
25 Guard { label, start: Instant::now() } 25 Guard { label, start: Instant::now() }
26} 26}
27 27
28/// Prints backtrace to stderr, useful for debugging.
29#[cfg(feature = "backtrace")]
30pub fn print_backtrace() {
31 let bt = backtrace::Backtrace::new();
32 eprintln!("{:?}", bt);
33}
34#[cfg(not(feature = "backtrace"))]
35pub fn print_backtrace() {
36 eprintln!(
37 r#"Enable the backtrace feature.
38Uncomment `default = [ "backtrace" ]` in `crates/stdx/Cargo.toml`.
39"#
40 );
41}
42
43pub fn to_lower_snake_case(s: &str) -> String {
44 to_snake_case(s, char::to_ascii_lowercase)
45}
46pub fn to_upper_snake_case(s: &str) -> String {
47 to_snake_case(s, char::to_ascii_uppercase)
48}
28fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String { 49fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
29 let mut buf = String::with_capacity(s.len()); 50 let mut buf = String::with_capacity(s.len());
30 let mut prev = false; 51 let mut prev = false;
@@ -43,14 +64,6 @@ fn to_snake_case<F: Fn(&char) -> char>(s: &str, change_case: F) -> String {
43 buf 64 buf
44} 65}
45 66
46pub fn to_lower_snake_case(s: &str) -> String {
47 to_snake_case(s, char::to_ascii_lowercase)
48}
49
50pub fn to_upper_snake_case(s: &str) -> String {
51 to_snake_case(s, char::to_ascii_uppercase)
52}
53
54pub fn replace(buf: &mut String, from: char, to: &str) { 67pub fn replace(buf: &mut String, from: char, to: &str) {
55 if !buf.contains(from) { 68 if !buf.contains(from) {
56 return; 69 return;