aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/cli/analysis_stats.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/cli/analysis_stats.rs')
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs59
1 files changed, 40 insertions, 19 deletions
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ddb3db6c3..10327ebb9 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -3,26 +3,27 @@
3 3
4use std::{path::Path, time::Instant}; 4use std::{path::Path, time::Instant};
5 5
6use itertools::Itertools;
7use rand::{seq::SliceRandom, thread_rng};
8use rayon::prelude::*;
9use rustc_hash::FxHashSet;
10
11use hir::{ 6use hir::{
12 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
13 original_range, AssocItem, Crate, HasSource, HirDisplay, ModuleDef, 8 original_range, AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
14}; 9};
15use hir_def::FunctionId; 10use hir_def::FunctionId;
16use hir_ty::{Ty, TypeWalk}; 11use hir_ty::{Ty, TypeWalk};
12use itertools::Itertools;
17use ra_db::{ 13use ra_db::{
18 salsa::{self, ParallelDatabase}, 14 salsa::{self, ParallelDatabase},
19 SourceDatabaseExt, 15 SourceDatabaseExt,
20}; 16};
21use ra_syntax::AstNode; 17use ra_syntax::AstNode;
18use rand::{seq::SliceRandom, thread_rng};
19use rayon::prelude::*;
20use rustc_hash::FxHashSet;
22use stdx::format_to; 21use stdx::format_to;
23 22
24use crate::{ 23use crate::{
25 cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}, 24 cli::{
25 load_cargo::load_cargo, progress_report::ProgressReport, report_metric, Result, Verbosity,
26 },
26 print_memory_usage, 27 print_memory_usage,
27}; 28};
28 29
@@ -48,7 +49,7 @@ pub fn analysis_stats(
48 let db_load_time = Instant::now(); 49 let db_load_time = Instant::now();
49 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; 50 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
50 let db = host.raw_database(); 51 let db = host.raw_database();
51 println!("Database loaded {:?}", db_load_time.elapsed()); 52 eprintln!("Database loaded {:?}", db_load_time.elapsed());
52 let analysis_time = Instant::now(); 53 let analysis_time = Instant::now();
53 let mut num_crates = 0; 54 let mut num_crates = 0;
54 let mut visited_modules = FxHashSet::default(); 55 let mut visited_modules = FxHashSet::default();
@@ -74,7 +75,7 @@ pub fn analysis_stats(
74 visit_queue.shuffle(&mut thread_rng()); 75 visit_queue.shuffle(&mut thread_rng());
75 } 76 }
76 77
77 println!("Crates in this dir: {}", num_crates); 78 eprintln!("Crates in this dir: {}", num_crates);
78 let mut num_decls = 0; 79 let mut num_decls = 0;
79 let mut funcs = Vec::new(); 80 let mut funcs = Vec::new();
80 while let Some(module) = visit_queue.pop() { 81 while let Some(module) = visit_queue.pop() {
@@ -98,10 +99,15 @@ pub fn analysis_stats(
98 } 99 }
99 } 100 }
100 } 101 }
101 println!("Total modules found: {}", visited_modules.len()); 102 eprintln!("Total modules found: {}", visited_modules.len());
102 println!("Total declarations: {}", num_decls); 103 eprintln!("Total declarations: {}", num_decls);
103 println!("Total functions: {}", funcs.len()); 104 eprintln!("Total functions: {}", funcs.len());
104 println!("Item Collection: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 105 let item_collection_memory = ra_prof::memory_usage();
106 eprintln!(
107 "Item Collection: {:?}, {}",
108 analysis_time.elapsed(),
109 item_collection_memory.allocated
110 );
105 111
106 if randomize { 112 if randomize {
107 funcs.shuffle(&mut thread_rng()); 113 funcs.shuffle(&mut thread_rng());
@@ -123,7 +129,11 @@ pub fn analysis_stats(
123 snap.0.infer(f_id.into()); 129 snap.0.infer(f_id.into());
124 }) 130 })
125 .count(); 131 .count();
126 println!("Parallel Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); 132 eprintln!(
133 "Parallel Inference: {:?}, {}",
134 inference_time.elapsed(),
135 ra_prof::memory_usage().allocated
136 );
127 } 137 }
128 138
129 let inference_time = Instant::now(); 139 let inference_time = Instant::now();
@@ -260,20 +270,31 @@ pub fn analysis_stats(
260 bar.inc(1); 270 bar.inc(1);
261 } 271 }
262 bar.finish_and_clear(); 272 bar.finish_and_clear();
263 println!("Total expressions: {}", num_exprs); 273 eprintln!("Total expressions: {}", num_exprs);
264 println!( 274 eprintln!(
265 "Expressions of unknown type: {} ({}%)", 275 "Expressions of unknown type: {} ({}%)",
266 num_exprs_unknown, 276 num_exprs_unknown,
267 if num_exprs > 0 { num_exprs_unknown * 100 / num_exprs } else { 100 } 277 if num_exprs > 0 { num_exprs_unknown * 100 / num_exprs } else { 100 }
268 ); 278 );
269 println!( 279 eprintln!(
270 "Expressions of partially unknown type: {} ({}%)", 280 "Expressions of partially unknown type: {} ({}%)",
271 num_exprs_partially_unknown, 281 num_exprs_partially_unknown,
272 if num_exprs > 0 { num_exprs_partially_unknown * 100 / num_exprs } else { 100 } 282 if num_exprs > 0 { num_exprs_partially_unknown * 100 / num_exprs } else { 100 }
273 ); 283 );
274 println!("Type mismatches: {}", num_type_mismatches); 284 eprintln!("Type mismatches: {}", num_type_mismatches);
275 println!("Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage()); 285
276 println!("Total: {:?}, {}", analysis_time.elapsed(), ra_prof::memory_usage()); 286 let inference_time = inference_time.elapsed();
287 let total_memory = ra_prof::memory_usage();
288 eprintln!(
289 "Inference: {:?}, {}",
290 inference_time,
291 total_memory.allocated - item_collection_memory.allocated
292 );
293
294 let analysis_time = analysis_time.elapsed();
295 eprintln!("Total: {:?}, {}", analysis_time, total_memory);
296 report_metric("total time", analysis_time.as_millis() as u64, "ms");
297 report_metric("total memory", total_memory.allocated.megabytes() as u64, "MB");
277 298
278 if memory_usage { 299 if memory_usage {
279 print_memory_usage(host, vfs); 300 print_memory_usage(host, vfs);