Add a command to compute memory usage statistics
This commit is contained in:
@@ -32,7 +32,7 @@ use crate::{
|
||||
cargo_target_spec::CargoTargetSpec,
|
||||
config::RustfmtConfig,
|
||||
from_json, from_proto,
|
||||
global_state::GlobalStateSnapshot,
|
||||
global_state::{GlobalState, GlobalStateSnapshot},
|
||||
lsp_ext::{self, InlayHint, InlayHintsParams},
|
||||
to_proto, LspError, Result,
|
||||
};
|
||||
@@ -62,6 +62,17 @@ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_memory_usage(state: &mut GlobalState, _: ()) -> Result<String> {
|
||||
let _p = profile("handle_memory_usage");
|
||||
let mem = state.analysis_host.per_query_memory_usage();
|
||||
|
||||
let mut out = String::new();
|
||||
for (name, bytes) in mem {
|
||||
format_to!(out, "{:>8} {}\n", bytes, name);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_syntax_tree(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::SyntaxTreeParams,
|
||||
|
||||
@@ -14,6 +14,14 @@ impl Request for AnalyzerStatus {
|
||||
const METHOD: &'static str = "rust-analyzer/analyzerStatus";
|
||||
}
|
||||
|
||||
pub enum MemoryUsage {}
|
||||
|
||||
impl Request for MemoryUsage {
|
||||
type Params = ();
|
||||
type Result = String;
|
||||
const METHOD: &'static str = "rust-analyzer/memoryUsage";
|
||||
}
|
||||
|
||||
pub enum ReloadWorkspace {}
|
||||
|
||||
impl Request for ReloadWorkspace {
|
||||
|
||||
@@ -341,6 +341,7 @@ impl GlobalState {
|
||||
.on_sync::<lsp_ext::MatchingBrace>(|s, p| {
|
||||
handlers::handle_matching_brace(s.snapshot(), p)
|
||||
})?
|
||||
.on_sync::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
|
||||
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)?
|
||||
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)?
|
||||
.on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)?
|
||||
|
||||
Reference in New Issue
Block a user