@@ -74,16 +74,16 @@ pub fn print_hir_stats(tcx: TyCtxt<'_>) {
74
74
} ;
75
75
tcx. hir ( ) . walk_toplevel_module ( & mut collector) ;
76
76
tcx. hir ( ) . walk_attributes ( & mut collector) ;
77
- collector. print ( "HIR STATS" ) ;
77
+ collector. print ( "HIR STATS" , "hir-stats" ) ;
78
78
}
79
79
80
- pub fn print_ast_stats ( krate : & ast:: Crate , title : & str ) {
80
+ pub fn print_ast_stats ( krate : & ast:: Crate , title : & str , prefix : & str ) {
81
81
use rustc_ast:: visit:: Visitor ;
82
82
83
83
let mut collector =
84
84
StatCollector { krate : None , nodes : FxHashMap :: default ( ) , seen : FxHashSet :: default ( ) } ;
85
85
collector. visit_crate ( krate) ;
86
- collector. print ( title) ;
86
+ collector. print ( title, prefix ) ;
87
87
}
88
88
89
89
impl < ' k > StatCollector < ' k > {
@@ -119,23 +119,26 @@ impl<'k> StatCollector<'k> {
119
119
}
120
120
}
121
121
122
- fn print ( & self , title : & str ) {
122
+ fn print ( & self , title : & str , prefix : & str ) {
123
123
let mut nodes: Vec < _ > = self . nodes . iter ( ) . collect ( ) ;
124
124
nodes. sort_by_key ( |& ( _, ref node) | node. stats . count * node. stats . size ) ;
125
125
126
126
let total_size = nodes. iter ( ) . map ( |( _, node) | node. stats . count * node. stats . size ) . sum ( ) ;
127
127
128
- eprintln ! ( "\n {}\n " , title) ;
129
-
130
- eprintln ! ( "{:<18}{:>18}{:>14}{:>14}" , "Name" , "Accumulated Size" , "Count" , "Item Size" ) ;
131
- eprintln ! ( "----------------------------------------------------------------" ) ;
128
+ eprintln ! ( "{} {}" , prefix, title) ;
129
+ eprintln ! (
130
+ "{} {:<18}{:>18}{:>14}{:>14}" ,
131
+ prefix, "Name" , "Accumulated Size" , "Count" , "Item Size"
132
+ ) ;
133
+ eprintln ! ( "{} ----------------------------------------------------------------" , prefix) ;
132
134
133
135
let percent = |m, n| ( m * 100 ) as f64 / n as f64 ;
134
136
135
137
for ( label, node) in nodes {
136
138
let size = node. stats . count * node. stats . size ;
137
139
eprintln ! (
138
- "{:<18}{:>10} ({:4.1}%){:>14}{:>14}" ,
140
+ "{} {:<18}{:>10} ({:4.1}%){:>14}{:>14}" ,
141
+ prefix,
139
142
label,
140
143
to_readable_str( size) ,
141
144
percent( size, total_size) ,
@@ -149,7 +152,8 @@ impl<'k> StatCollector<'k> {
149
152
for ( label, subnode) in subnodes {
150
153
let size = subnode. count * subnode. size ;
151
154
eprintln ! (
152
- "- {:<18}{:>10} ({:4.1}%){:>14}" ,
155
+ "{} - {:<18}{:>10} ({:4.1}%){:>14}" ,
156
+ prefix,
153
157
label,
154
158
to_readable_str( size) ,
155
159
percent( size, total_size) ,
@@ -158,8 +162,9 @@ impl<'k> StatCollector<'k> {
158
162
}
159
163
}
160
164
}
161
- eprintln ! ( "----------------------------------------------------------------" ) ;
162
- eprintln ! ( "{:<18}{:>10}\n " , "Total" , to_readable_str( total_size) ) ;
165
+ eprintln ! ( "{} ----------------------------------------------------------------" , prefix) ;
166
+ eprintln ! ( "{} {:<18}{:>10}" , prefix, "Total" , to_readable_str( total_size) ) ;
167
+ eprintln ! ( "{}" , prefix) ;
163
168
}
164
169
}
165
170
0 commit comments