aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-14 21:04:08 +0100
committerAleksey Kladov <[email protected]>2019-04-14 23:10:07 +0100
commitb228947b6863f5864b48bb3a7f3dcca921f58d0b (patch)
tree208d849b755a91e2f3640c1550ca8c74192a579a
parente6f32c6d3a5626a1f071d96d2cdebe630abdd5a3 (diff)
cleanup syntax
-rw-r--r--crates/ra_lsp_server/src/main.rs28
-rw-r--r--crates/ra_prof/src/lib.rs4
-rw-r--r--docs/dev/README.md10
3 files changed, 34 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs
index 4646742ca..28f9985b6 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/main.rs
@@ -12,15 +12,27 @@ fn main() -> Result<()> {
12 Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?, 12 Ok(ref v) if v == "1" => logger.log_to_file().directory("log").start()?,
13 _ => logger.start()?, 13 _ => logger.start()?,
14 }; 14 };
15 let prof_depth = match std::env::var("RA_PROFILE_DEPTH") { 15 // Filtering syntax
16 Ok(ref d) => d.parse()?, 16 // env RA_PROFILE=* // dump everything
17 _ => 0, 17 // env RA_PROFILE=foo|bar|baz // enabled only selected entries
18 }; 18 // env RA_PROFILE=*@3 // dump everything, up to depth 3
19 let profile_allowed = match std::env::var("RA_PROFILE") { 19 let filter = match std::env::var("RA_PROFILE") {
20 Ok(ref p) => p.split(";").map(String::from).collect(), 20 Ok(p) => {
21 _ => Vec::new(), 21 let mut p = p.as_str();
22 let depth = if let Some(idx) = p.rfind("@") {
23 let depth: usize = p[idx + 1..].parse().expect("invalid profile depth");
24 p = &p[..idx];
25 depth
26 } else {
27 999
28 };
29 let allowed =
30 if p == "*" { Vec::new() } else { p.split(";").map(String::from).collect() };
31 ra_prof::Filter::new(depth, allowed)
32 }
33 Err(_) => ra_prof::Filter::disabled(),
22 }; 34 };
23 ra_prof::set_filter(ra_prof::Filter::new(prof_depth, profile_allowed)); 35 ra_prof::set_filter(filter);
24 log::info!("lifecycle: server started"); 36 log::info!("lifecycle: server started");
25 match ::std::panic::catch_unwind(main_inner) { 37 match ::std::panic::catch_unwind(main_inner) {
26 Ok(res) => { 38 Ok(res) => {
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index 121a62813..c7c21b6d2 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -104,6 +104,10 @@ pub struct Filter {
104} 104}
105 105
106impl Filter { 106impl Filter {
107 pub fn disabled() -> Filter {
108 Filter::new(0, Vec::new())
109 }
110
107 pub fn new(depth: usize, allowed: Vec<String>) -> Filter { 111 pub fn new(depth: usize, allowed: Vec<String>) -> Filter {
108 Filter { depth, allowed } 112 Filter { depth, allowed }
109 } 113 }
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 7bb323f3f..7fb5886c9 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -135,3 +135,13 @@ There's also two VS Code commands which might be of interest:
135 There's an alias for this: `cargo jinstall-lsp`. 135 There's an alias for this: `cargo jinstall-lsp`.
136 136
137* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection. 137* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
138
139# Profiling
140
141We have a built-in hierarchical profiler, you can enable it by using `RA_PROF` env-var:
142
143```
144RA_PROFILE=* // dump everything
145RA_PROFILE=foo|bar|baz // enabled only selected entries
146RA_PROFILE=*@3 // dump everything, up to depth 3
147```