aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-07 12:00:04 +0100
committerGitHub <[email protected]>2020-07-07 12:00:04 +0100
commit73e972a173523fd37224c1b6649e0690d2fcdbec (patch)
tree563aa911598649e4c4a1f5719b5fe63a863f14a8 /crates
parent0719f2824c01839c19fee944e9f15d15409d74d4 (diff)
parentf44c4b61e131284287b24dea6da6324cbe9cb252 (diff)
Merge #5244
5244: Add a command to compute memory usage statistics r=matklad a=jonas-schievink This allows inspecting memory usage on a live rust-analyzer instance after it has been used interactively. This will only work with `--features jemalloc`, so maybe it should print something more useful when that's not available? Right now it will just print 0 Bytes for every query. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_db/src/change.rs9
-rw-r--r--crates/rust-analyzer/src/handlers.rs13
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs8
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
4 files changed, 30 insertions, 1 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index d8da3f949..84c6f40ff 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -164,6 +164,15 @@ impl RootDatabase {
164 hir::db::BodyQuery.in_db(self).sweep(sweep); 164 hir::db::BodyQuery.in_db(self).sweep(sweep);
165 } 165 }
166 166
167 // Feature: Memory Usage
168 //
169 // Clears rust-analyzer's internal database and prints memory usage statistics.
170 //
171 // |===
172 // | Editor | Action Name
173 //
174 // | VS Code | **Rust Analyzer: Memory Usage (Clears Database)**
175 // |===
167 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { 176 pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> {
168 let mut acc: Vec<(String, Bytes)> = vec![]; 177 let mut acc: Vec<(String, Bytes)> = vec![];
169 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 178 let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index cc83a1406..f374334fe 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -32,7 +32,7 @@ use crate::{
32 cargo_target_spec::CargoTargetSpec, 32 cargo_target_spec::CargoTargetSpec,
33 config::RustfmtConfig, 33 config::RustfmtConfig,
34 from_json, from_proto, 34 from_json, from_proto,
35 global_state::GlobalStateSnapshot, 35 global_state::{GlobalState, GlobalStateSnapshot},
36 lsp_ext::{self, InlayHint, InlayHintsParams}, 36 lsp_ext::{self, InlayHint, InlayHintsParams},
37 to_proto, LspError, Result, 37 to_proto, LspError, Result,
38}; 38};
@@ -62,6 +62,17 @@ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result
62 Ok(buf) 62 Ok(buf)
63} 63}
64 64
65pub(crate) fn handle_memory_usage(state: &mut GlobalState, _: ()) -> Result<String> {
66 let _p = profile("handle_memory_usage");
67 let mem = state.analysis_host.per_query_memory_usage();
68
69 let mut out = String::new();
70 for (name, bytes) in mem {
71 format_to!(out, "{:>8} {}\n", bytes, name);
72 }
73 Ok(out)
74}
75
65pub(crate) fn handle_syntax_tree( 76pub(crate) fn handle_syntax_tree(
66 snap: GlobalStateSnapshot, 77 snap: GlobalStateSnapshot,
67 params: lsp_ext::SyntaxTreeParams, 78 params: lsp_ext::SyntaxTreeParams,
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index d225ad5ff..ba8a0231f 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -14,6 +14,14 @@ impl Request for AnalyzerStatus {
14 const METHOD: &'static str = "rust-analyzer/analyzerStatus"; 14 const METHOD: &'static str = "rust-analyzer/analyzerStatus";
15} 15}
16 16
17pub enum MemoryUsage {}
18
19impl Request for MemoryUsage {
20 type Params = ();
21 type Result = String;
22 const METHOD: &'static str = "rust-analyzer/memoryUsage";
23}
24
17pub enum ReloadWorkspace {} 25pub enum ReloadWorkspace {}
18 26
19impl Request for ReloadWorkspace { 27impl Request for ReloadWorkspace {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index cfde55431..5900886e7 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -341,6 +341,7 @@ impl GlobalState {
341 .on_sync::<lsp_ext::MatchingBrace>(|s, p| { 341 .on_sync::<lsp_ext::MatchingBrace>(|s, p| {
342 handlers::handle_matching_brace(s.snapshot(), p) 342 handlers::handle_matching_brace(s.snapshot(), p)
343 })? 343 })?
344 .on_sync::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
344 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)? 345 .on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)?
345 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)? 346 .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)?
346 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)? 347 .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)?