Skip to content

Commit 9fd4e5c

Browse files
committed
Improve analysis stats legibility
1 parent 3aa153b commit 9fd4e5c

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl AnalysisStatsCmd {
5858
let mut db_load_sw = self.stop_watch();
5959
let (host, vfs) = load_cargo(&self.path, self.load_output_dirs, self.with_proc_macro)?;
6060
let db = host.raw_database();
61-
eprintln!("Database loaded {}", db_load_sw.elapsed());
61+
eprintln!("{:<20} {}", "Database loaded:", db_load_sw.elapsed());
6262

6363
let mut analysis_sw = self.stop_watch();
6464
let mut num_crates = 0;
@@ -85,7 +85,7 @@ impl AnalysisStatsCmd {
8585
shuffle(&mut rng, &mut visit_queue);
8686
}
8787

88-
eprintln!("Crates in this dir: {}", num_crates);
88+
eprint!(" crates: {}", num_crates);
8989
let mut num_decls = 0;
9090
let mut funcs = Vec::new();
9191
while let Some(module) = visit_queue.pop() {
@@ -109,10 +109,8 @@ impl AnalysisStatsCmd {
109109
}
110110
}
111111
}
112-
eprintln!("Total modules found: {}", visited_modules.len());
113-
eprintln!("Total declarations: {}", num_decls);
114-
eprintln!("Total functions: {}", funcs.len());
115-
eprintln!("Item Collection: {}", analysis_sw.elapsed());
112+
eprintln!(", mods: {}, decls: {}, fns: {}", visited_modules.len(), num_decls, funcs.len());
113+
eprintln!("{:<20} {}", "Item Collection:", analysis_sw.elapsed());
116114

117115
if self.randomize {
118116
shuffle(&mut rng, &mut funcs);
@@ -135,7 +133,7 @@ impl AnalysisStatsCmd {
135133
snap.0.infer(f_id.into());
136134
})
137135
.count();
138-
eprintln!("Parallel Inference: {}", inference_sw.elapsed());
136+
eprintln!("{:<20} {}", "Parallel Inference:", inference_sw.elapsed());
139137
}
140138

141139
let mut inference_sw = self.stop_watch();
@@ -273,27 +271,22 @@ impl AnalysisStatsCmd {
273271
bar.inc(1);
274272
}
275273
bar.finish_and_clear();
276-
eprintln!("Total expressions: {}", num_exprs);
277274
eprintln!(
278-
"Expressions of unknown type: {} ({}%)",
275+
" exprs: {}, ??ty: {} ({}%), ?ty: {} ({}%), !ty: {}",
276+
num_exprs,
279277
num_exprs_unknown,
280-
if num_exprs > 0 { num_exprs_unknown * 100 / num_exprs } else { 100 }
281-
);
282-
report_metric("unknown type", num_exprs_unknown, "#");
283-
284-
eprintln!(
285-
"Expressions of partially unknown type: {} ({}%)",
278+
percentage(num_exprs_unknown, num_exprs),
286279
num_exprs_partially_unknown,
287-
if num_exprs > 0 { num_exprs_partially_unknown * 100 / num_exprs } else { 100 }
280+
percentage(num_exprs_partially_unknown, num_exprs),
281+
num_type_mismatches
288282
);
289-
290-
eprintln!("Type mismatches: {}", num_type_mismatches);
283+
report_metric("unknown type", num_exprs_unknown, "#");
291284
report_metric("type mismatches", num_type_mismatches, "#");
292285

293-
eprintln!("Inference: {}", inference_sw.elapsed());
286+
eprintln!("{:<20} {}", "Inference:", inference_sw.elapsed());
294287

295288
let total_span = analysis_sw.elapsed();
296-
eprintln!("Total: {}", total_span);
289+
eprintln!("{:<20} {}", "Total:", total_span);
297290
report_metric("total time", total_span.time.as_millis() as u64, "ms");
298291
if let Some(instructions) = total_span.instructions {
299292
report_metric("total instructions", instructions, "#instr");
@@ -325,3 +318,7 @@ fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
325318
slice.swap(0, idx);
326319
}
327320
}
321+
322+
fn percentage(n: u64, total: u64) -> u64 {
323+
(n * 100).checked_div(total).unwrap_or(100)
324+
}

0 commit comments

Comments
 (0)