Tweak -Zinput-stats and -Zmeta-stats output.
To make it match `-Zmacro-stats`, and work better if you have enabled it for multiple crates. - Print each crate's name. - Print a `===` banner at the start and end for separation.
This commit is contained in:
parent
1e7e1732ca
commit
b2a57e6b42
4 changed files with 17 additions and 13 deletions
|
|
@ -370,7 +370,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
|
|||
let mut lint_buffer = resolver.lint_buffer.steal();
|
||||
|
||||
if sess.opts.unstable_opts.input_stats {
|
||||
input_stats::print_ast_stats(krate);
|
||||
input_stats::print_ast_stats(tcx, krate);
|
||||
}
|
||||
|
||||
// Needs to go *after* expansion to be able to check the results of macro expansion.
|
||||
|
|
|
|||
|
|
@ -794,7 +794,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
// `RUSTFLAGS='-Zmeta-stats' cargo build`). It still doesn't guarantee
|
||||
// non-interleaving, though.
|
||||
let mut s = String::new();
|
||||
_ = writeln!(s, "{prefix} METADATA STATS");
|
||||
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
|
||||
_ = writeln!(s, "{prefix} METADATA STATS: {}", tcx.crate_name(LOCAL_CRATE));
|
||||
_ = writeln!(s, "{prefix} {:<section_w$}{:>size_w$}", "Section", "Size");
|
||||
_ = writeln!(s, "{prefix} {}", "-".repeat(banner_w));
|
||||
for (label, size) in stats {
|
||||
|
|
@ -814,7 +815,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
usize_with_underscores(total_bytes),
|
||||
perc(zero_bytes)
|
||||
);
|
||||
_ = writeln!(s, "{prefix}");
|
||||
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
|
||||
eprint!("{s}");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,16 +65,16 @@ pub fn print_hir_stats(tcx: TyCtxt<'_>) {
|
|||
StatCollector { tcx: Some(tcx), nodes: FxHashMap::default(), seen: FxHashSet::default() };
|
||||
tcx.hir_walk_toplevel_module(&mut collector);
|
||||
tcx.hir_walk_attributes(&mut collector);
|
||||
collector.print("HIR STATS", "hir-stats");
|
||||
collector.print(tcx, "HIR STATS", "hir-stats");
|
||||
}
|
||||
|
||||
pub fn print_ast_stats(krate: &ast::Crate) {
|
||||
pub fn print_ast_stats(tcx: TyCtxt<'_>, krate: &ast::Crate) {
|
||||
use rustc_ast::visit::Visitor;
|
||||
|
||||
let mut collector =
|
||||
StatCollector { tcx: None, nodes: FxHashMap::default(), seen: FxHashSet::default() };
|
||||
collector.visit_crate(krate);
|
||||
collector.print("POST EXPANSION AST STATS", "ast-stats");
|
||||
collector.print(tcx, "POST EXPANSION AST STATS", "ast-stats");
|
||||
}
|
||||
|
||||
impl<'k> StatCollector<'k> {
|
||||
|
|
@ -116,7 +116,7 @@ impl<'k> StatCollector<'k> {
|
|||
}
|
||||
}
|
||||
|
||||
fn print(&self, title: &str, prefix: &str) {
|
||||
fn print(&self, tcx: TyCtxt<'_>, title: &str, prefix: &str) {
|
||||
use std::fmt::Write;
|
||||
|
||||
// We will soon sort, so the initial order does not matter.
|
||||
|
|
@ -142,7 +142,8 @@ impl<'k> StatCollector<'k> {
|
|||
// `RUSTFLAGS='-Zinput-stats' cargo build`). It still doesn't guarantee
|
||||
// non-interleaving, though.
|
||||
let mut s = String::new();
|
||||
_ = writeln!(s, "{prefix} {title}");
|
||||
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
|
||||
_ = writeln!(s, "{prefix} {title}: {}", tcx.crate_name(hir::def_id::LOCAL_CRATE));
|
||||
_ = writeln!(
|
||||
s,
|
||||
"{prefix} {:<name_w$}{:>acc_size_w$}{:>count_w$}{:>item_size_w$}",
|
||||
|
|
@ -193,7 +194,7 @@ impl<'k> StatCollector<'k> {
|
|||
"",
|
||||
usize_with_underscores(total_count),
|
||||
);
|
||||
_ = writeln!(s, "{prefix}");
|
||||
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
|
||||
eprint!("{s}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
ast-stats POST EXPANSION AST STATS
|
||||
ast-stats ================================================================
|
||||
ast-stats POST EXPANSION AST STATS: input_stats
|
||||
ast-stats Name Accumulated Size Count Item Size
|
||||
ast-stats ----------------------------------------------------------------
|
||||
ast-stats Item 1_584 (NN.N%) 11 144
|
||||
|
|
@ -57,8 +58,9 @@ ast-stats - AngleBracketed 40 (NN.N%) 1
|
|||
ast-stats Crate 40 (NN.N%) 1 40
|
||||
ast-stats ----------------------------------------------------------------
|
||||
ast-stats Total 7_416 127
|
||||
ast-stats
|
||||
hir-stats HIR STATS
|
||||
ast-stats ================================================================
|
||||
hir-stats ================================================================
|
||||
hir-stats HIR STATS: input_stats
|
||||
hir-stats Name Accumulated Size Count Item Size
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats PathSegment 1_776 (NN.N%) 37 48
|
||||
|
|
@ -118,4 +120,4 @@ hir-stats Lifetime 28 (NN.N%) 1 28
|
|||
hir-stats ForeignItemRef 24 (NN.N%) 1 24
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats Total 8_676 172
|
||||
hir-stats
|
||||
hir-stats ================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue