aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/cli.rs23
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs5
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs8
-rw-r--r--crates/rust-analyzer/src/lib.rs21
-rw-r--r--xtask/src/metrics.rs9
5 files changed, 29 insertions, 37 deletions
diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs
index 6966ee576..6879a462d 100644
--- a/crates/rust-analyzer/src/cli.rs
+++ b/crates/rust-analyzer/src/cli.rs
@@ -10,8 +10,9 @@ mod ssr;
10use std::io::Read; 10use std::io::Read;
11 11
12use anyhow::Result; 12use anyhow::Result;
13use ide::Analysis; 13use ide::{Analysis, AnalysisHost};
14use syntax::{AstNode, SourceFile}; 14use syntax::{AstNode, SourceFile};
15use vfs::Vfs;
15 16
16pub use self::{ 17pub use self::{
17 analysis_bench::{BenchCmd, BenchWhat, Position}, 18 analysis_bench::{BenchCmd, BenchWhat, Position},
@@ -82,3 +83,23 @@ fn report_metric(metric: &str, value: u64, unit: &str) {
82 } 83 }
83 println!("METRIC:{}:{}:{}", metric, value, unit) 84 println!("METRIC:{}:{}:{}", metric, value, unit)
84} 85}
86
87fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
88 let mut mem = host.per_query_memory_usage();
89
90 let before = profile::memory_usage();
91 drop(vfs);
92 let vfs = before.allocated - profile::memory_usage().allocated;
93 mem.push(("VFS".into(), vfs));
94
95 let before = profile::memory_usage();
96 drop(host);
97 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
98
99 mem.push(("Remaining".into(), profile::memory_usage().allocated));
100
101 for (name, bytes) in mem {
102 // NOTE: Not a debug print, so avoid going through the `eprintln` defined above.
103 eprintln!("{:>8} {}", bytes, name);
104 }
105}
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 8e33986d5..5a8484c62 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -12,10 +12,7 @@ use ide_db::base_db::{
12}; 12};
13use vfs::AbsPathBuf; 13use vfs::AbsPathBuf;
14 14
15use crate::{ 15use crate::cli::{load_cargo::load_cargo, print_memory_usage, Verbosity};
16 cli::{load_cargo::load_cargo, Verbosity},
17 print_memory_usage,
18};
19 16
20pub struct BenchCmd { 17pub struct BenchCmd {
21 pub path: PathBuf, 18 pub path: PathBuf,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 58d284d47..a23fb7a33 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -23,11 +23,9 @@ use rustc_hash::FxHashSet;
23use stdx::format_to; 23use stdx::format_to;
24use syntax::AstNode; 24use syntax::AstNode;
25 25
26use crate::{ 26use crate::cli::{
27 cli::{ 27 load_cargo::load_cargo, print_memory_usage, progress_report::ProgressReport, report_metric,
28 load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity, 28 Result, Verbosity,
29 },
30 print_memory_usage,
31}; 29};
32use profile::StopWatch; 30use profile::StopWatch;
33 31
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index ad08f1afb..79fe30e53 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -37,10 +37,8 @@ mod document;
37pub mod lsp_ext; 37pub mod lsp_ext;
38pub mod config; 38pub mod config;
39 39
40use ide::AnalysisHost;
41use serde::de::DeserializeOwned; 40use serde::de::DeserializeOwned;
42use std::fmt; 41use std::fmt;
43use vfs::Vfs;
44 42
45pub use crate::{caps::server_capabilities, main_loop::main_loop}; 43pub use crate::{caps::server_capabilities, main_loop::main_loop};
46 44
@@ -72,22 +70,3 @@ impl fmt::Display for LspError {
72} 70}
73 71
74impl std::error::Error for LspError {} 72impl std::error::Error for LspError {}
75
76fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
77 let mut mem = host.per_query_memory_usage();
78
79 let before = profile::memory_usage();
80 drop(vfs);
81 let vfs = before.allocated - profile::memory_usage().allocated;
82 mem.push(("VFS".into(), vfs));
83
84 let before = profile::memory_usage();
85 drop(host);
86 mem.push(("Unaccounted".into(), before.allocated - profile::memory_usage().allocated));
87
88 mem.push(("Remaining".into(), profile::memory_usage().allocated));
89
90 for (name, bytes) in mem {
91 eprintln!("{:>8} {}", bytes, name);
92 }
93}
diff --git a/xtask/src/metrics.rs b/xtask/src/metrics.rs
index 40fc6e622..624ad3b7e 100644
--- a/xtask/src/metrics.rs
+++ b/xtask/src/metrics.rs
@@ -3,7 +3,6 @@ use std::{
3 env, 3 env,
4 io::Write as _, 4 io::Write as _,
5 path::Path, 5 path::Path,
6 process::{Command, Stdio},
7 time::{Instant, SystemTime, UNIX_EPOCH}, 6 time::{Instant, SystemTime, UNIX_EPOCH},
8}; 7};
9 8
@@ -82,11 +81,9 @@ impl Metrics {
82 } 81 }
83 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> { 82 fn measure_analysis_stats_path(&mut self, name: &str, path: &str) -> Result<()> {
84 eprintln!("\nMeasuring analysis-stats/{}", name); 83 eprintln!("\nMeasuring analysis-stats/{}", name);
85 let output = Command::new("./target/release/rust-analyzer") 84 let output =
86 .args(&["analysis-stats", "--quiet", "--memory-usage", path]) 85 cmd!("./target/release/rust-analyzer analysis-stats --quiet --memory-usage {path}")
87 .stderr(Stdio::inherit()) 86 .read()?;
88 .output()?;
89 let output = String::from_utf8(output.stdout)?;
90 for (metric, value, unit) in parse_metrics(&output) { 87 for (metric, value, unit) in parse_metrics(&output) {
91 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into()); 88 self.report(&format!("analysis-stats/{}/{}", name, metric), value, unit.into());
92 } 89 }