Add percentages to -Zhir-stats output.

This commit is contained in:
Nicholas Nethercote 2022-08-11 13:46:26 +10:00
parent 6a3c663cbb
commit 85c749266d
2 changed files with 78 additions and 76 deletions

View File

@ -86,26 +86,28 @@ impl<'k> StatCollector<'k> {
stats.sort_by_key(|&(_, ref d)| d.count * d.size);
let mut total_size = 0;
let total_size = stats.iter().map(|(_, data)| data.count * data.size).sum();
eprintln!("\n{}\n", title);
eprintln!("{:<18}{:>18}{:>14}{:>14}", "Name", "Accumulated Size", "Count", "Item Size");
eprintln!("----------------------------------------------------------------");
let percent = |m, n| { (m * 100) as f64 / n as f64 };
for (label, data) in stats {
let size = data.count * data.size;
eprintln!(
"{:<18}{:>18}{:>14}{:>14}",
"{:<18}{:>10} ({:4.1}%){:>14}{:>14}",
label,
to_readable_str(data.count * data.size),
to_readable_str(size),
percent(size, total_size),
to_readable_str(data.count),
to_readable_str(data.size)
);
total_size += data.count * data.size;
}
eprintln!("----------------------------------------------------------------");
eprintln!("{:<18}{:>18}\n", "Total", to_readable_str(total_size));
eprintln!("{:<18}{:>10}\n", "Total", to_readable_str(total_size));
}
}

View File

@ -3,89 +3,89 @@ PRE EXPANSION AST STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
ExprField 48 1 48
GenericArgs 64 1 64
Local 72 1 72
WherePredicate 72 1 72
Crate 72 1 72
Arm 96 2 48
FieldDef 160 2 80
ForeignItem 160 1 160
Stmt 160 5 32
Param 160 4 40
FnDecl 200 5 40
Variant 240 2 120
Block 288 6 48
Attribute 304 2 152
GenericBound 352 4 88
GenericParam 520 5 104
AssocItem 640 4 160
PathSegment 720 30 24
Expr 832 8 104
Pat 840 7 120
Ty 1_344 14 96
Item 1_800 9 200
ExprField 48 ( 0.5%) 1 48
GenericArgs 64 ( 0.7%) 1 64
Local 72 ( 0.8%) 1 72
WherePredicate 72 ( 0.8%) 1 72
Crate 72 ( 0.8%) 1 72
Arm 96 ( 1.0%) 2 48
FieldDef 160 ( 1.7%) 2 80
ForeignItem 160 ( 1.7%) 1 160
Stmt 160 ( 1.7%) 5 32
Param 160 ( 1.7%) 4 40
FnDecl 200 ( 2.2%) 5 40
Variant 240 ( 2.6%) 2 120
Block 288 ( 3.1%) 6 48
Attribute 304 ( 3.3%) 2 152
GenericBound 352 ( 3.8%) 4 88
GenericParam 520 ( 5.7%) 5 104
AssocItem 640 ( 7.0%) 4 160
PathSegment 720 ( 7.9%) 30 24
Expr 832 ( 9.1%) 8 104
Pat 840 ( 9.2%) 7 120
Ty 1_344 (14.7%) 14 96
Item 1_800 (19.7%) 9 200
----------------------------------------------------------------
Total 9_144
Total 9_144
POST EXPANSION AST STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
ExprField 48 1 48
GenericArgs 64 1 64
Local 72 1 72
WherePredicate 72 1 72
Crate 72 1 72
Arm 96 2 48
InlineAsm 120 1 120
FieldDef 160 2 80
ForeignItem 160 1 160
Stmt 160 5 32
Param 160 4 40
FnDecl 200 5 40
Variant 240 2 120
Block 288 6 48
GenericBound 352 4 88
GenericParam 520 5 104
Attribute 608 4 152
AssocItem 640 4 160
PathSegment 792 33 24
Pat 840 7 120
Expr 936 9 104
Ty 1_344 14 96
Item 2_200 11 200
ExprField 48 ( 0.5%) 1 48
GenericArgs 64 ( 0.6%) 1 64
Local 72 ( 0.7%) 1 72
WherePredicate 72 ( 0.7%) 1 72
Crate 72 ( 0.7%) 1 72
Arm 96 ( 0.9%) 2 48
InlineAsm 120 ( 1.2%) 1 120
FieldDef 160 ( 1.6%) 2 80
ForeignItem 160 ( 1.6%) 1 160
Stmt 160 ( 1.6%) 5 32
Param 160 ( 1.6%) 4 40
FnDecl 200 ( 2.0%) 5 40
Variant 240 ( 2.4%) 2 120
Block 288 ( 2.8%) 6 48
GenericBound 352 ( 3.5%) 4 88
GenericParam 520 ( 5.1%) 5 104
Attribute 608 ( 6.0%) 4 152
AssocItem 640 ( 6.3%) 4 160
PathSegment 792 ( 7.8%) 33 24
Pat 840 ( 8.3%) 7 120
Expr 936 ( 9.2%) 9 104
Ty 1_344 (13.2%) 14 96
Item 2_200 (21.7%) 11 200
----------------------------------------------------------------
Total 10_144
Total 10_144
HIR STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
Param 64 2 32
Local 64 1 64
ForeignItem 72 1 72
FieldDef 96 2 48
Arm 96 2 48
Stmt 96 3 32
FnDecl 120 3 40
Lifetime 128 4 32
Variant 160 2 80
ImplItem 176 2 88
GenericBound 192 4 48
TraitItem 192 2 96
WherePredicate 216 3 72
Block 288 6 48
QPath 408 17 24
Pat 440 5 88
Attribute 608 4 152
Expr 672 12 56
Item 960 12 80
Ty 1_152 16 72
Path 1_296 27 48
PathSegment 2_240 40 56
Param 64 ( 0.7%) 2 32
Local 64 ( 0.7%) 1 64
ForeignItem 72 ( 0.7%) 1 72
FieldDef 96 ( 1.0%) 2 48
Arm 96 ( 1.0%) 2 48
Stmt 96 ( 1.0%) 3 32
FnDecl 120 ( 1.2%) 3 40
Lifetime 128 ( 1.3%) 4 32
Variant 160 ( 1.6%) 2 80
ImplItem 176 ( 1.8%) 2 88
GenericBound 192 ( 2.0%) 4 48
TraitItem 192 ( 2.0%) 2 96
WherePredicate 216 ( 2.2%) 3 72
Block 288 ( 3.0%) 6 48
QPath 408 ( 4.2%) 17 24
Pat 440 ( 4.5%) 5 88
Attribute 608 ( 6.2%) 4 152
Expr 672 ( 6.9%) 12 56
Item 960 ( 9.9%) 12 80
Ty 1_152 (11.8%) 16 72
Path 1_296 (13.3%) 27 48
PathSegment 2_240 (23.0%) 40 56
----------------------------------------------------------------
Total 9_736
Total 9_736