Skip to content

Commit 85c7492

Browse files
committed
Add percentages to -Zhir-stats output.
1 parent 6a3c663 commit 85c7492

File tree

2 files changed

+78
-76
lines changed

2 files changed

+78
-76
lines changed

compiler/rustc_passes/src/hir_stats.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,28 @@ impl<'k> StatCollector<'k> {
8686

8787
stats.sort_by_key(|&(_, ref d)| d.count * d.size);
8888

89-
let mut total_size = 0;
89+
let total_size = stats.iter().map(|(_, data)| data.count * data.size).sum();
9090

9191
eprintln!("\n{}\n", title);
9292

9393
eprintln!("{:<18}{:>18}{:>14}{:>14}", "Name", "Accumulated Size", "Count", "Item Size");
9494
eprintln!("----------------------------------------------------------------");
9595

96+
let percent = |m, n| { (m * 100) as f64 / n as f64 };
97+
9698
for (label, data) in stats {
99+
let size = data.count * data.size;
97100
eprintln!(
98-
"{:<18}{:>18}{:>14}{:>14}",
101+
"{:<18}{:>10} ({:4.1}%){:>14}{:>14}",
99102
label,
100-
to_readable_str(data.count * data.size),
103+
to_readable_str(size),
104+
percent(size, total_size),
101105
to_readable_str(data.count),
102106
to_readable_str(data.size)
103107
);
104-
105-
total_size += data.count * data.size;
106108
}
107109
eprintln!("----------------------------------------------------------------");
108-
eprintln!("{:<18}{:>18}\n", "Total", to_readable_str(total_size));
110+
eprintln!("{:<18}{:>10}\n", "Total", to_readable_str(total_size));
109111
}
110112
}
111113

src/test/ui/stats/hir-stats.stderr

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,89 @@ PRE EXPANSION AST STATS
33

44
Name Accumulated Size Count Item Size
55
----------------------------------------------------------------
6-
ExprField 48 1 48
7-
GenericArgs 64 1 64
8-
Local 72 1 72
9-
WherePredicate 72 1 72
10-
Crate 72 1 72
11-
Arm 96 2 48
12-
FieldDef 160 2 80
13-
ForeignItem 160 1 160
14-
Stmt 160 5 32
15-
Param 160 4 40
16-
FnDecl 200 5 40
17-
Variant 240 2 120
18-
Block 288 6 48
19-
Attribute 304 2 152
20-
GenericBound 352 4 88
21-
GenericParam 520 5 104
22-
AssocItem 640 4 160
23-
PathSegment 720 30 24
24-
Expr 832 8 104
25-
Pat 840 7 120
26-
Ty 1_344 14 96
27-
Item 1_800 9 200
6+
ExprField 48 ( 0.5%) 1 48
7+
GenericArgs 64 ( 0.7%) 1 64
8+
Local 72 ( 0.8%) 1 72
9+
WherePredicate 72 ( 0.8%) 1 72
10+
Crate 72 ( 0.8%) 1 72
11+
Arm 96 ( 1.0%) 2 48
12+
FieldDef 160 ( 1.7%) 2 80
13+
ForeignItem 160 ( 1.7%) 1 160
14+
Stmt 160 ( 1.7%) 5 32
15+
Param 160 ( 1.7%) 4 40
16+
FnDecl 200 ( 2.2%) 5 40
17+
Variant 240 ( 2.6%) 2 120
18+
Block 288 ( 3.1%) 6 48
19+
Attribute 304 ( 3.3%) 2 152
20+
GenericBound 352 ( 3.8%) 4 88
21+
GenericParam 520 ( 5.7%) 5 104
22+
AssocItem 640 ( 7.0%) 4 160
23+
PathSegment 720 ( 7.9%) 30 24
24+
Expr 832 ( 9.1%) 8 104
25+
Pat 840 ( 9.2%) 7 120
26+
Ty 1_344 (14.7%) 14 96
27+
Item 1_800 (19.7%) 9 200
2828
----------------------------------------------------------------
29-
Total 9_144
29+
Total 9_144
3030

3131

3232
POST EXPANSION AST STATS
3333

3434
Name Accumulated Size Count Item Size
3535
----------------------------------------------------------------
36-
ExprField 48 1 48
37-
GenericArgs 64 1 64
38-
Local 72 1 72
39-
WherePredicate 72 1 72
40-
Crate 72 1 72
41-
Arm 96 2 48
42-
InlineAsm 120 1 120
43-
FieldDef 160 2 80
44-
ForeignItem 160 1 160
45-
Stmt 160 5 32
46-
Param 160 4 40
47-
FnDecl 200 5 40
48-
Variant 240 2 120
49-
Block 288 6 48
50-
GenericBound 352 4 88
51-
GenericParam 520 5 104
52-
Attribute 608 4 152
53-
AssocItem 640 4 160
54-
PathSegment 792 33 24
55-
Pat 840 7 120
56-
Expr 936 9 104
57-
Ty 1_344 14 96
58-
Item 2_200 11 200
36+
ExprField 48 ( 0.5%) 1 48
37+
GenericArgs 64 ( 0.6%) 1 64
38+
Local 72 ( 0.7%) 1 72
39+
WherePredicate 72 ( 0.7%) 1 72
40+
Crate 72 ( 0.7%) 1 72
41+
Arm 96 ( 0.9%) 2 48
42+
InlineAsm 120 ( 1.2%) 1 120
43+
FieldDef 160 ( 1.6%) 2 80
44+
ForeignItem 160 ( 1.6%) 1 160
45+
Stmt 160 ( 1.6%) 5 32
46+
Param 160 ( 1.6%) 4 40
47+
FnDecl 200 ( 2.0%) 5 40
48+
Variant 240 ( 2.4%) 2 120
49+
Block 288 ( 2.8%) 6 48
50+
GenericBound 352 ( 3.5%) 4 88
51+
GenericParam 520 ( 5.1%) 5 104
52+
Attribute 608 ( 6.0%) 4 152
53+
AssocItem 640 ( 6.3%) 4 160
54+
PathSegment 792 ( 7.8%) 33 24
55+
Pat 840 ( 8.3%) 7 120
56+
Expr 936 ( 9.2%) 9 104
57+
Ty 1_344 (13.2%) 14 96
58+
Item 2_200 (21.7%) 11 200
5959
----------------------------------------------------------------
60-
Total 10_144
60+
Total 10_144
6161

6262

6363
HIR STATS
6464

6565
Name Accumulated Size Count Item Size
6666
----------------------------------------------------------------
67-
Param 64 2 32
68-
Local 64 1 64
69-
ForeignItem 72 1 72
70-
FieldDef 96 2 48
71-
Arm 96 2 48
72-
Stmt 96 3 32
73-
FnDecl 120 3 40
74-
Lifetime 128 4 32
75-
Variant 160 2 80
76-
ImplItem 176 2 88
77-
GenericBound 192 4 48
78-
TraitItem 192 2 96
79-
WherePredicate 216 3 72
80-
Block 288 6 48
81-
QPath 408 17 24
82-
Pat 440 5 88
83-
Attribute 608 4 152
84-
Expr 672 12 56
85-
Item 960 12 80
86-
Ty 1_152 16 72
87-
Path 1_296 27 48
88-
PathSegment 2_240 40 56
67+
Param 64 ( 0.7%) 2 32
68+
Local 64 ( 0.7%) 1 64
69+
ForeignItem 72 ( 0.7%) 1 72
70+
FieldDef 96 ( 1.0%) 2 48
71+
Arm 96 ( 1.0%) 2 48
72+
Stmt 96 ( 1.0%) 3 32
73+
FnDecl 120 ( 1.2%) 3 40
74+
Lifetime 128 ( 1.3%) 4 32
75+
Variant 160 ( 1.6%) 2 80
76+
ImplItem 176 ( 1.8%) 2 88
77+
GenericBound 192 ( 2.0%) 4 48
78+
TraitItem 192 ( 2.0%) 2 96
79+
WherePredicate 216 ( 2.2%) 3 72
80+
Block 288 ( 3.0%) 6 48
81+
QPath 408 ( 4.2%) 17 24
82+
Pat 440 ( 4.5%) 5 88
83+
Attribute 608 ( 6.2%) 4 152
84+
Expr 672 ( 6.9%) 12 56
85+
Item 960 ( 9.9%) 12 80
86+
Ty 1_152 (11.8%) 16 72
87+
Path 1_296 (13.3%) 27 48
88+
PathSegment 2_240 (23.0%) 40 56
8989
----------------------------------------------------------------
90-
Total 9_736
90+
Total 9_736
9191

0 commit comments

Comments
 (0)