aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-15 13:07:05 +0100
committerGitHub <[email protected]>2020-07-15 13:07:05 +0100
commit2c67ca0146c215df908de0066b124d63d2ba8fe7 (patch)
treee88964c096e95c76f554f3deea2514355ad2ef4c /crates
parent6f3c8dc11d477a6d680ce018e93f007c31499bd5 (diff)
parent9086c8c6632b4e2aa480311152f91b2ed2f1288c (diff)
Merge #5387
5387: Add --memory-usage to analysis-bench r=matklad a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/bin/args.rs7
-rw-r--r--crates/rust-analyzer/src/bin/main.rs3
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs11
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs24
-rw-r--r--crates/rust-analyzer/src/lib.rs21
5 files changed, 44 insertions, 22 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index d0e566f47..3210416ee 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -35,6 +35,7 @@ pub(crate) enum Command {
35 with_proc_macro: bool, 35 with_proc_macro: bool,
36 }, 36 },
37 Bench { 37 Bench {
38 memory_usage: bool,
38 path: PathBuf, 39 path: PathBuf,
39 what: BenchWhat, 40 what: BenchWhat,
40 load_output_dirs: bool, 41 load_output_dirs: bool,
@@ -165,7 +166,7 @@ USAGE:
165FLAGS: 166FLAGS:
166 -o, --only Only analyze items matching this path 167 -o, --only Only analyze items matching this path
167 -h, --help Prints help information 168 -h, --help Prints help information
168 --memory-usage Collect memory usage statistics (requires `--feature jemalloc`) 169 --memory-usage Collect memory usage statistics (requires `--features jemalloc`)
169 --randomize Randomize order in which crates, modules, and items are processed 170 --randomize Randomize order in which crates, modules, and items are processed
170 --parallel Run type inference in parallel 171 --parallel Run type inference in parallel
171 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 172 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
@@ -220,6 +221,7 @@ USAGE:
220 221
221FLAGS: 222FLAGS:
222 -h, --help Prints help information 223 -h, --help Prints help information
224 --memory-usage Collect memory usage statistics (requires `--features jemalloc`)
223 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 225 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
224 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding 226 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
225 -v, --verbose 227 -v, --verbose
@@ -251,9 +253,10 @@ ARGS:
251 "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" 253 "exactly one of `--highlight`, `--complete` or `--goto-def` must be set"
252 ), 254 ),
253 }; 255 };
256 let memory_usage = matches.contains("--memory-usage");
254 let load_output_dirs = matches.contains("--load-output-dirs"); 257 let load_output_dirs = matches.contains("--load-output-dirs");
255 let with_proc_macro = matches.contains("--with-proc-macro"); 258 let with_proc_macro = matches.contains("--with-proc-macro");
256 Command::Bench { path, what, load_output_dirs, with_proc_macro } 259 Command::Bench { memory_usage, path, what, load_output_dirs, with_proc_macro }
257 } 260 }
258 "diagnostics" => { 261 "diagnostics" => {
259 if matches.contains(["-h", "--help"]) { 262 if matches.contains(["-h", "--help"]) {
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 65f1a6d15..408892eab 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -49,11 +49,12 @@ fn main() -> Result<()> {
49 load_output_dirs, 49 load_output_dirs,
50 with_proc_macro, 50 with_proc_macro,
51 )?, 51 )?,
52 args::Command::Bench { path, what, load_output_dirs, with_proc_macro } => { 52 args::Command::Bench { memory_usage, path, what, load_output_dirs, with_proc_macro } => {
53 cli::analysis_bench( 53 cli::analysis_bench(
54 args.verbosity, 54 args.verbosity,
55 path.as_ref(), 55 path.as_ref(),
56 what, 56 what,
57 memory_usage,
57 load_output_dirs, 58 load_output_dirs,
58 with_proc_macro, 59 with_proc_macro,
59 )? 60 )?
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index a93d5fb73..9299879b7 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -10,7 +10,10 @@ use ra_db::{
10use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosition, LineCol}; 10use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionConfig, FilePosition, LineCol};
11use vfs::AbsPathBuf; 11use vfs::AbsPathBuf;
12 12
13use crate::cli::{load_cargo::load_cargo, Verbosity}; 13use crate::{
14 cli::{load_cargo::load_cargo, Verbosity},
15 print_memory_usage,
16};
14 17
15pub enum BenchWhat { 18pub enum BenchWhat {
16 Highlight { path: AbsPathBuf }, 19 Highlight { path: AbsPathBuf },
@@ -44,6 +47,7 @@ pub fn analysis_bench(
44 verbosity: Verbosity, 47 verbosity: Verbosity,
45 path: &Path, 48 path: &Path,
46 what: BenchWhat, 49 what: BenchWhat,
50 memory_usage: bool,
47 load_output_dirs: bool, 51 load_output_dirs: bool,
48 with_proc_macro: bool, 52 with_proc_macro: bool,
49) -> Result<()> { 53) -> Result<()> {
@@ -99,6 +103,11 @@ pub fn analysis_bench(
99 } 103 }
100 } 104 }
101 } 105 }
106
107 if memory_usage {
108 print_memory_usage(host, vfs);
109 }
110
102 Ok(()) 111 Ok(())
103} 112}
104 113
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 846264046..ddb3db6c3 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -21,7 +21,10 @@ use ra_db::{
21use ra_syntax::AstNode; 21use ra_syntax::AstNode;
22use stdx::format_to; 22use stdx::format_to;
23 23
24use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; 24use crate::{
25 cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity},
26 print_memory_usage,
27};
25 28
26/// Need to wrap Snapshot to provide `Clone` impl for `map_with` 29/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
27struct Snap<DB>(DB); 30struct Snap<DB>(DB);
@@ -43,7 +46,7 @@ pub fn analysis_stats(
43 with_proc_macro: bool, 46 with_proc_macro: bool,
44) -> Result<()> { 47) -> Result<()> {
45 let db_load_time = Instant::now(); 48 let db_load_time = Instant::now();
46 let (mut host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; 49 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
47 let db = host.raw_database(); 50 let db = host.raw_database();
48 println!("Database loaded {:?}", db_load_time.elapsed()); 51 println!("Database loaded {:?}", db_load_time.elapsed());
49 let analysis_time = Instant::now(); 52 let analysis_time = Instant::now();
@@ -273,22 +276,7 @@ pub fn analysis_stats(
273 println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 276 println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage());
274 277
275 if memory_usage { 278 if memory_usage {
276 let mut mem = host.per_query_memory_usage(); 279 print_memory_usage(host, vfs);
277
278 let before = ra_prof::memory_usage();
279 drop(vfs);
280 let vfs = before.allocated - ra_prof::memory_usage().allocated;
281 mem.push(("VFS".into(), vfs));
282
283 let before = ra_prof::memory_usage();
284 drop(host);
285 mem.push(("Unaccounted".into(), before.allocated - ra_prof::memory_usage().allocated));
286
287 mem.push(("Remaining".into(), ra_prof::memory_usage().allocated));
288
289 for (name, bytes) in mem {
290 println!("{:>8} {}", bytes, name)
291 }
292 } 280 }
293 281
294 Ok(()) 282 Ok(())
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index 407944d85..369830973 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -40,7 +40,9 @@ use serde::de::DeserializeOwned;
40 40
41pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>; 41pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
42pub use crate::{caps::server_capabilities, main_loop::main_loop}; 42pub use crate::{caps::server_capabilities, main_loop::main_loop};
43use ra_ide::AnalysisHost;
43use std::fmt; 44use std::fmt;
45use vfs::Vfs;
44 46
45pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> { 47pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
46 let res = T::deserialize(&json) 48 let res = T::deserialize(&json)
@@ -67,3 +69,22 @@ impl fmt::Display for LspError {
67} 69}
68 70
69impl std::error::Error for LspError {} 71impl std::error::Error for LspError {}
72
73fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) {
74 let mut mem = host.per_query_memory_usage();
75
76 let before = ra_prof::memory_usage();
77 drop(vfs);
78 let vfs = before.allocated - ra_prof::memory_usage().allocated;
79 mem.push(("VFS".into(), vfs));
80
81 let before = ra_prof::memory_usage();
82 drop(host);
83 mem.push(("Unaccounted".into(), before.allocated - ra_prof::memory_usage().allocated));
84
85 mem.push(("Remaining".into(), ra_prof::memory_usage().allocated));
86
87 for (name, bytes) in mem {
88 println!("{:>8} {}", bytes, name);
89 }
90}