From 22624ade4891a203971b53a900501a92d612f1fe Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 14 Mar 2025 14:03:50 -0400 Subject: [PATCH 1/6] analysis-stats: emit lines of code and item tree counts for workspace; dependencies --- .../rust-analyzer/src/cli/analysis_stats.rs | 87 +++++++++++++------ 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index 29331000a119..74d791318849 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -118,27 +118,67 @@ impl flags::AnalysisStats { } let mut item_tree_sw = self.stop_watch(); - let mut num_item_trees = 0; let source_roots = krates .iter() .cloned() .map(|krate| db.file_source_root(krate.root_file(db)).source_root_id(db)) .unique(); + + let mut dep_loc = 0; + let mut workspace_loc = 0; + let mut deps_item_trees = 0; + let mut workspace_item_trees = 0; + for source_root_id in source_roots { let source_root = db.source_root(source_root_id).source_root(db); - if !source_root.is_library || self.with_deps { - for file_id in source_root.iter() { - if let Some(p) = source_root.path_for_file(&file_id) { - if let Some((_, Some("rs"))) = p.name_and_extension() { + for file_id in source_root.iter() { + if let Some(p) = source_root.path_for_file(&file_id) { + if let Some((_, Some("rs"))) = p.name_and_extension() { + // measure workspace/project code + if !source_root.is_library || self.with_deps { + let length = db.file_text(file_id).text(db).lines().count(); db.file_item_tree(EditionedFileId::current_edition(file_id).into()); - num_item_trees += 1; + + workspace_loc += length; + workspace_item_trees += 1; + } else if self.source_stats { + let length = db.file_text(file_id).text(db).lines().count(); + db.file_item_tree(EditionedFileId::current_edition(file_id).into()); + + dep_loc += length; + deps_item_trees += 1 } } } } } - eprintln!(" item trees: {num_item_trees}"); + eprintln!(" item trees: {workspace_item_trees}"); let item_tree_time = item_tree_sw.elapsed(); + + if self.source_stats { + eprintln!("Source stats:"); + eprintln!(" dependency lines of code: {dep_loc}, item trees: {deps_item_trees}"); + eprintln!( + " workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}" + ); + + // FIXME(salsa-transition): bring back stats for ParseQuery (file size) + // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement + // Salsa's memory usage tracking works with tracked functions. + + // let mut total_file_size = Bytes::default(); + // for e in ide_db::base_db::ParseQuery.in_db(db).entries::>() { + // total_file_size += syntax_len(db.parse(e.key).syntax_node()) + // } + + // let mut total_macro_file_size = Bytes::default(); + // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::>() { + // let val = db.parse_macro_expansion(e.key).value.0; + // total_macro_file_size += syntax_len(val.syntax_node()) + // } + // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); + } + eprintln!("{:<20} {}", "Item Tree Collection:", item_tree_time); report_metric("item tree time", item_tree_time.time.as_millis() as u64, "ms"); @@ -168,6 +208,11 @@ impl flags::AnalysisStats { let mut bodies = Vec::new(); let mut adts = Vec::new(); let mut file_ids = Vec::new(); + + let mut num_traits = 0; + let mut num_macro_rules_macros = 0; + let mut num_proc_macros = 0; + while let Some(module) = visit_queue.pop() { if visited_modules.insert(module) { file_ids.extend(module.as_source_file_id(db)); @@ -189,6 +234,14 @@ impl flags::AnalysisStats { bodies.push(DefWithBody::from(c)); } ModuleDef::Static(s) => bodies.push(DefWithBody::from(s)), + ModuleDef::Trait(_) => num_traits += 1, + ModuleDef::Macro(m) => match m.kind(db) { + hir::MacroKind::Declarative => num_macro_rules_macros += 1, + hir::MacroKind::Derive + | hir::MacroKind::Attr + | hir::MacroKind::ProcMacro => num_proc_macros += 1, + _ => (), + }, _ => (), }; } @@ -217,6 +270,8 @@ impl flags::AnalysisStats { .filter(|it| matches!(it, DefWithBody::Const(_) | DefWithBody::Static(_))) .count(), ); + eprintln!(" traits: {num_traits}, macro_rules macros: {num_macro_rules_macros}, proc_macros: {num_proc_macros}"); + let crate_def_map_time = crate_def_map_sw.elapsed(); eprintln!("{:<20} {}", "Item Collection:", crate_def_map_time); report_metric("crate def map time", crate_def_map_time.time.as_millis() as u64, "ms"); @@ -264,24 +319,6 @@ impl flags::AnalysisStats { } report_metric("total memory", total_span.memory.allocated.megabytes() as u64, "MB"); - if self.source_stats { - // FIXME(salsa-transition): bring back stats for ParseQuery (file size) - // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement - // Salsa's memory usage tracking works with tracked functions. - - // let mut total_file_size = Bytes::default(); - // for e in ide_db::base_db::ParseQuery.in_db(db).entries::>() { - // total_file_size += syntax_len(db.parse(e.key).syntax_node()) - // } - - // let mut total_macro_file_size = Bytes::default(); - // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::>() { - // let val = db.parse_macro_expansion(e.key).value.0; - // total_macro_file_size += syntax_len(val.syntax_node()) - // } - // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); - } - if verbosity.is_verbose() { print_memory_usage(host, vfs); } From efe3fe76ea699b51c4da6e6c98c0b03b1eddb59f Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 14 Mar 2025 15:27:56 -0400 Subject: [PATCH 2/6] analysis-stats: always print source stats --- .../rust-analyzer/src/cli/analysis_stats.rs | 40 +++++++++---------- .../crates/rust-analyzer/src/cli/flags.rs | 3 -- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index 74d791318849..97a319f03125 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -141,7 +141,7 @@ impl flags::AnalysisStats { workspace_loc += length; workspace_item_trees += 1; - } else if self.source_stats { + } else { let length = db.file_text(file_id).text(db).lines().count(); db.file_item_tree(EditionedFileId::current_edition(file_id).into()); @@ -155,29 +155,25 @@ impl flags::AnalysisStats { eprintln!(" item trees: {workspace_item_trees}"); let item_tree_time = item_tree_sw.elapsed(); - if self.source_stats { - eprintln!("Source stats:"); - eprintln!(" dependency lines of code: {dep_loc}, item trees: {deps_item_trees}"); - eprintln!( - " workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}" - ); + eprintln!("Source stats:"); + eprintln!(" dependency lines of code: {dep_loc}, item trees: {deps_item_trees}"); + eprintln!(" workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}"); - // FIXME(salsa-transition): bring back stats for ParseQuery (file size) - // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement - // Salsa's memory usage tracking works with tracked functions. + // FIXME(salsa-transition): bring back stats for ParseQuery (file size) + // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement + // Salsa's memory usage tracking works with tracked functions. - // let mut total_file_size = Bytes::default(); - // for e in ide_db::base_db::ParseQuery.in_db(db).entries::>() { - // total_file_size += syntax_len(db.parse(e.key).syntax_node()) - // } + // let mut total_file_size = Bytes::default(); + // for e in ide_db::base_db::ParseQuery.in_db(db).entries::>() { + // total_file_size += syntax_len(db.parse(e.key).syntax_node()) + // } - // let mut total_macro_file_size = Bytes::default(); - // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::>() { - // let val = db.parse_macro_expansion(e.key).value.0; - // total_macro_file_size += syntax_len(val.syntax_node()) - // } - // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); - } + // let mut total_macro_file_size = Bytes::default(); + // for e in hir::db::ParseMacroExpansionQuery.in_db(db).entries::>() { + // let val = db.parse_macro_expansion(e.key).value.0; + // total_macro_file_size += syntax_len(val.syntax_node()) + // } + // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); eprintln!("{:<20} {}", "Item Tree Collection:", item_tree_time); report_metric("item tree time", item_tree_time.time.as_millis() as u64, "ms"); @@ -261,7 +257,7 @@ impl flags::AnalysisStats { } } eprintln!( - ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {}", + ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {},", visited_modules.len(), bodies.len(), adts.len(), diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs index ff24602144a9..13075d499422 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs @@ -62,8 +62,6 @@ xflags::xflags! { optional --randomize /// Run type inference in parallel. optional --parallel - /// Print the total length of all source and macro files (whitespace is not counted). - optional --source-stats /// Only analyze items matching this path. optional -o, --only path: String @@ -231,7 +229,6 @@ pub struct AnalysisStats { pub output: Option, pub randomize: bool, pub parallel: bool, - pub source_stats: bool, pub only: Option, pub with_deps: bool, pub no_sysroot: bool, From 44a5b14ca253728381368a6afce68017058c25d5 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 14 Mar 2025 15:57:47 -0400 Subject: [PATCH 3/6] analysis-stats: add `UsizeWithUnderscore` for readability of large numbers --- .../rust-analyzer/src/cli/analysis_stats.rs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index 97a319f03125..c5186d85d556 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -2,7 +2,7 @@ //! errors. use std::{ - env, + env, fmt, time::{SystemTime, UNIX_EPOCH}, }; @@ -156,6 +156,11 @@ impl flags::AnalysisStats { let item_tree_time = item_tree_sw.elapsed(); eprintln!("Source stats:"); + let dep_loc = UsizeWithUnderscore(dep_loc); + let deps_item_trees = UsizeWithUnderscore(deps_item_trees); + let workspace_loc = UsizeWithUnderscore(workspace_loc); + let workspace_item_trees = UsizeWithUnderscore(workspace_item_trees); + eprintln!(" dependency lines of code: {dep_loc}, item trees: {deps_item_trees}"); eprintln!(" workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}"); @@ -1250,6 +1255,30 @@ fn percentage(n: u64, total: u64) -> u64 { (n * 100).checked_div(total).unwrap_or(100) } +struct UsizeWithUnderscore(usize); + +impl fmt::Display for UsizeWithUnderscore { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let num_str = self.0.to_string(); + + if num_str.len() <= 3 { + return write!(f, "{}", num_str); + } + + let mut result = String::new(); + + for (count, ch) in num_str.chars().rev().enumerate() { + if count > 0 && count % 3 == 0 { + result.push('_'); + } + result.push(ch); + } + + let result = result.chars().rev().collect::(); + write!(f, "{}", result) + } +} + // FIXME(salsa-transition): bring this back whenever we implement // Salsa's memory usage tracking to work with tracked functions. // fn syntax_len(node: SyntaxNode) -> usize { From 12dc311eb83d20e3241bdf7817eb4d11b03f4aee Mon Sep 17 00:00:00 2001 From: David Barsky Date: Fri, 14 Mar 2025 17:53:17 -0400 Subject: [PATCH 4/6] analysis-stats: cleanup printing of some workspace stats --- .../rust-analyzer/src/cli/analysis_stats.rs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index c5186d85d556..bca44f958868 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -126,7 +126,7 @@ impl flags::AnalysisStats { let mut dep_loc = 0; let mut workspace_loc = 0; - let mut deps_item_trees = 0; + let mut dep_item_trees = 0; let mut workspace_item_trees = 0; for source_root_id in source_roots { @@ -146,7 +146,7 @@ impl flags::AnalysisStats { db.file_item_tree(EditionedFileId::current_edition(file_id).into()); dep_loc += length; - deps_item_trees += 1 + dep_item_trees += 1 } } } @@ -156,16 +156,19 @@ impl flags::AnalysisStats { let item_tree_time = item_tree_sw.elapsed(); eprintln!("Source stats:"); - let dep_loc = UsizeWithUnderscore(dep_loc); - let deps_item_trees = UsizeWithUnderscore(deps_item_trees); - let workspace_loc = UsizeWithUnderscore(workspace_loc); - let workspace_item_trees = UsizeWithUnderscore(workspace_item_trees); - - eprintln!(" dependency lines of code: {dep_loc}, item trees: {deps_item_trees}"); - eprintln!(" workspace lines of code: {workspace_loc}, item trees: {workspace_item_trees}"); + eprintln!( + " dependency lines of code: {}, item trees: {}", + UsizeWithUnderscore(dep_loc), + UsizeWithUnderscore(dep_item_trees), + ); + eprintln!( + " workspace lines of code: {}, item trees: {}", + UsizeWithUnderscore(workspace_loc), + UsizeWithUnderscore(workspace_item_trees), + ); // FIXME(salsa-transition): bring back stats for ParseQuery (file size) - // and ParseMacroExpansionQuery (mcaro expansion "file") size whenever we implement + // and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement // Salsa's memory usage tracking works with tracked functions. // let mut total_file_size = Bytes::default(); @@ -180,7 +183,7 @@ impl flags::AnalysisStats { // } // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); - eprintln!("{:<20} {}", "Item Tree Collection:", item_tree_time); + eprintln!("{:<20} {}", "Item Tree Collection (workspace):", item_tree_time); report_metric("item tree time", item_tree_time.time.as_millis() as u64, "ms"); let mut crate_def_map_sw = self.stop_watch(); From fe192932a9bdc77dd56e5b3d989e223b565eca51 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Sat, 15 Mar 2025 11:19:25 -0400 Subject: [PATCH 5/6] analysis-stats: expose and print some limited statistics from `hir-def` --- .../crates/hir-def/src/item_tree.rs | 25 +++++++ .../rust-analyzer/src/cli/analysis_stats.rs | 68 ++++++++++++++++++- 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs index ea87b0f70006..2debbb1ee4e3 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs @@ -218,6 +218,22 @@ impl ItemTree { Attrs::filter(db, krate, self.raw_attrs(of).clone()) } + /// Returns a count of a few, expensive items. + /// + /// For more detail, see [`ItemTreeDataStats`]. + pub fn item_tree_stats(&self) -> ItemTreeDataStats { + match self.data { + Some(ref data) => ItemTreeDataStats { + traits: data.traits.len(), + impls: data.impls.len(), + mods: data.mods.len(), + macro_calls: data.macro_calls.len(), + macro_rules: data.macro_rules.len(), + }, + None => ItemTreeDataStats::default(), + } + } + pub fn pretty_print(&self, db: &dyn DefDatabase, edition: Edition) -> String { pretty::print_item_tree(db, self, edition) } @@ -328,6 +344,15 @@ struct ItemTreeData { vis: ItemVisibilities, } +#[derive(Default, Debug, Eq, PartialEq)] +pub struct ItemTreeDataStats { + pub traits: usize, + pub impls: usize, + pub mods: usize, + pub macro_calls: usize, + pub macro_rules: usize, +} + #[derive(Default, Debug, Eq, PartialEq)] pub struct ItemTreeSourceMaps { all_concatenated: Box<[TypesSourceMap]>, diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index bca44f958868..ec232d8e85c3 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -3,6 +3,7 @@ use std::{ env, fmt, + ops::AddAssign, time::{SystemTime, UNIX_EPOCH}, }; @@ -129,6 +130,9 @@ impl flags::AnalysisStats { let mut dep_item_trees = 0; let mut workspace_item_trees = 0; + let mut workspace_item_stats = PrettyItemStats::default(); + let mut dep_item_stats = PrettyItemStats::default(); + for source_root_id in source_roots { let source_root = db.source_root(source_root_id).source_root(db); for file_id in source_root.iter() { @@ -137,16 +141,24 @@ impl flags::AnalysisStats { // measure workspace/project code if !source_root.is_library || self.with_deps { let length = db.file_text(file_id).text(db).lines().count(); - db.file_item_tree(EditionedFileId::current_edition(file_id).into()); + let item_stats = db + .file_item_tree(EditionedFileId::current_edition(file_id).into()) + .item_tree_stats() + .into(); workspace_loc += length; workspace_item_trees += 1; + workspace_item_stats += item_stats; } else { let length = db.file_text(file_id).text(db).lines().count(); - db.file_item_tree(EditionedFileId::current_edition(file_id).into()); + let item_stats = db + .file_item_tree(EditionedFileId::current_edition(file_id).into()) + .item_tree_stats() + .into(); dep_loc += length; - dep_item_trees += 1 + dep_item_trees += 1; + dep_item_stats += item_stats; } } } @@ -161,11 +173,13 @@ impl flags::AnalysisStats { UsizeWithUnderscore(dep_loc), UsizeWithUnderscore(dep_item_trees), ); + eprintln!(" dependency item stats: {}", dep_item_stats); eprintln!( " workspace lines of code: {}, item trees: {}", UsizeWithUnderscore(workspace_loc), UsizeWithUnderscore(workspace_item_trees), ); + eprintln!(" workspace stats: {}", workspace_item_stats); // FIXME(salsa-transition): bring back stats for ParseQuery (file size) // and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement @@ -1258,6 +1272,7 @@ fn percentage(n: u64, total: u64) -> u64 { (n * 100).checked_div(total).unwrap_or(100) } +#[derive(Default, Debug, Eq, PartialEq)] struct UsizeWithUnderscore(usize); impl fmt::Display for UsizeWithUnderscore { @@ -1282,6 +1297,53 @@ impl fmt::Display for UsizeWithUnderscore { } } +impl std::ops::AddAssign for UsizeWithUnderscore { + fn add_assign(&mut self, other: UsizeWithUnderscore) { + self.0 += other.0; + } +} + +#[derive(Default, Debug, Eq, PartialEq)] +struct PrettyItemStats { + traits: UsizeWithUnderscore, + impls: UsizeWithUnderscore, + mods: UsizeWithUnderscore, + macro_calls: UsizeWithUnderscore, + macro_rules: UsizeWithUnderscore, +} + +impl From for PrettyItemStats { + fn from(value: hir_def::item_tree::ItemTreeDataStats) -> Self { + Self { + traits: UsizeWithUnderscore(value.traits), + impls: UsizeWithUnderscore(value.impls), + mods: UsizeWithUnderscore(value.mods), + macro_calls: UsizeWithUnderscore(value.macro_calls), + macro_rules: UsizeWithUnderscore(value.macro_rules), + } + } +} + +impl AddAssign for PrettyItemStats { + fn add_assign(&mut self, rhs: Self) { + self.traits += rhs.traits; + self.impls += rhs.impls; + self.mods += rhs.mods; + self.macro_calls += rhs.macro_calls; + self.macro_rules += rhs.macro_rules; + } +} + +impl fmt::Display for PrettyItemStats { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "traits: {}, impl: {}, mods: {}, macro calls: {}, macro rules: {}", + self.traits, self.impls, self.mods, self.macro_calls, self.macro_rules + ) + } +} + // FIXME(salsa-transition): bring this back whenever we implement // Salsa's memory usage tracking to work with tracked functions. // fn syntax_len(node: SyntaxNode) -> usize { From 0add1a492f12bae00e1bae7afc5b32f5c670e13b Mon Sep 17 00:00:00 2001 From: David Barsky Date: Mon, 24 Mar 2025 12:30:41 -0700 Subject: [PATCH 6/6] analysis-stats: redesign printing of item tree stats --- .../rust-analyzer/src/cli/analysis_stats.rs | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs index ec232d8e85c3..66334e773814 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -167,19 +167,12 @@ impl flags::AnalysisStats { eprintln!(" item trees: {workspace_item_trees}"); let item_tree_time = item_tree_sw.elapsed(); - eprintln!("Source stats:"); eprintln!( " dependency lines of code: {}, item trees: {}", UsizeWithUnderscore(dep_loc), UsizeWithUnderscore(dep_item_trees), ); eprintln!(" dependency item stats: {}", dep_item_stats); - eprintln!( - " workspace lines of code: {}, item trees: {}", - UsizeWithUnderscore(workspace_loc), - UsizeWithUnderscore(workspace_item_trees), - ); - eprintln!(" workspace stats: {}", workspace_item_stats); // FIXME(salsa-transition): bring back stats for ParseQuery (file size) // and ParseMacroExpansionQuery (macro expansion "file") size whenever we implement @@ -197,8 +190,9 @@ impl flags::AnalysisStats { // } // eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}"); - eprintln!("{:<20} {}", "Item Tree Collection (workspace):", item_tree_time); + eprintln!("{:<20} {}", "Item Tree Collection:", item_tree_time); report_metric("item tree time", item_tree_time.time.as_millis() as u64, "ms"); + eprintln!(" Total Statistics:"); let mut crate_def_map_sw = self.stop_watch(); let mut num_crates = 0; @@ -221,7 +215,7 @@ impl flags::AnalysisStats { shuffle(&mut rng, &mut visit_queue); } - eprint!(" crates: {num_crates}"); + eprint!(" crates: {num_crates}"); let mut num_decls = 0; let mut bodies = Vec::new(); let mut adts = Vec::new(); @@ -279,7 +273,7 @@ impl flags::AnalysisStats { } } eprintln!( - ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {},", + ", mods: {}, decls: {num_decls}, bodies: {}, adts: {}, consts: {}", visited_modules.len(), bodies.len(), adts.len(), @@ -288,7 +282,25 @@ impl flags::AnalysisStats { .filter(|it| matches!(it, DefWithBody::Const(_) | DefWithBody::Static(_))) .count(), ); - eprintln!(" traits: {num_traits}, macro_rules macros: {num_macro_rules_macros}, proc_macros: {num_proc_macros}"); + + eprintln!(" Workspace:"); + eprintln!( + " traits: {num_traits}, macro_rules macros: {num_macro_rules_macros}, proc_macros: {num_proc_macros}" + ); + eprintln!( + " lines of code: {}, item trees: {}", + UsizeWithUnderscore(workspace_loc), + UsizeWithUnderscore(workspace_item_trees), + ); + eprintln!(" usages: {}", workspace_item_stats); + + eprintln!(" Dependencies:"); + eprintln!( + " lines of code: {}, item trees: {}", + UsizeWithUnderscore(dep_loc), + UsizeWithUnderscore(dep_item_trees), + ); + eprintln!(" declarations: {}", dep_item_stats); let crate_def_map_time = crate_def_map_sw.elapsed(); eprintln!("{:<20} {}", "Item Collection:", crate_def_map_time);