mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
add mir-stats to analysis-stats
This commit is contained in:
parent
b7b9ae59a0
commit
1b85b43e6f
2 changed files with 26 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
//! errors.
|
//! errors.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
env,
|
env,
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
@ -153,6 +154,10 @@ impl flags::AnalysisStats {
|
||||||
self.run_inference(&host, db, &vfs, &funcs, verbosity);
|
self.run_inference(&host, db, &vfs, &funcs, verbosity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.mir_stats {
|
||||||
|
self.lower_mir(db, &funcs);
|
||||||
|
}
|
||||||
|
|
||||||
let total_span = analysis_sw.elapsed();
|
let total_span = analysis_sw.elapsed();
|
||||||
eprintln!("{:<20} {total_span}", "Total:");
|
eprintln!("{:<20} {total_span}", "Total:");
|
||||||
report_metric("total time", total_span.time.as_millis() as u64, "ms");
|
report_metric("total time", total_span.time.as_millis() as u64, "ms");
|
||||||
|
@ -189,6 +194,24 @@ impl flags::AnalysisStats {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lower_mir(&self, db: &RootDatabase, funcs: &[Function]) {
|
||||||
|
let all = funcs.len();
|
||||||
|
let mut fail = 0;
|
||||||
|
let mut h: HashMap<String, usize> = HashMap::new();
|
||||||
|
for f in funcs {
|
||||||
|
let f = FunctionId::from(*f);
|
||||||
|
let Err(e) = db.mir_body(f.into()) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let es = format!("{:?}", e);
|
||||||
|
*h.entry(es).or_default() += 1;
|
||||||
|
fail += 1;
|
||||||
|
}
|
||||||
|
let h = h.into_iter().sorted_by_key(|x| x.1).collect::<Vec<_>>();
|
||||||
|
eprintln!("Mir failed reasons: {:#?}", h);
|
||||||
|
eprintln!("Mir failed bodies: {fail} ({}%)", fail * 100 / all);
|
||||||
|
}
|
||||||
|
|
||||||
fn run_inference(
|
fn run_inference(
|
||||||
&self,
|
&self,
|
||||||
host: &AnalysisHost,
|
host: &AnalysisHost,
|
||||||
|
|
|
@ -66,6 +66,8 @@ xflags::xflags! {
|
||||||
optional --memory-usage
|
optional --memory-usage
|
||||||
/// Print the total length of all source and macro files (whitespace is not counted).
|
/// Print the total length of all source and macro files (whitespace is not counted).
|
||||||
optional --source-stats
|
optional --source-stats
|
||||||
|
/// Print the number of bodies that fail to lower to mir, in addition to failed reasons.
|
||||||
|
optional --mir-stats
|
||||||
|
|
||||||
/// Only analyze items matching this path.
|
/// Only analyze items matching this path.
|
||||||
optional -o, --only path: String
|
optional -o, --only path: String
|
||||||
|
@ -172,6 +174,7 @@ pub struct AnalysisStats {
|
||||||
pub parallel: bool,
|
pub parallel: bool,
|
||||||
pub memory_usage: bool,
|
pub memory_usage: bool,
|
||||||
pub source_stats: bool,
|
pub source_stats: bool,
|
||||||
|
pub mir_stats: bool,
|
||||||
pub only: Option<String>,
|
pub only: Option<String>,
|
||||||
pub with_deps: bool,
|
pub with_deps: bool,
|
||||||
pub no_sysroot: bool,
|
pub no_sysroot: bool,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue