@@ -74,16 +74,16 @@ pub fn print_hir_stats(tcx: TyCtxt<'_>) {
7474 } ;
7575 tcx. hir ( ) . walk_toplevel_module ( & mut collector) ;
7676 tcx. hir ( ) . walk_attributes ( & mut collector) ;
77- collector. print ( "HIR STATS" ) ;
77+ collector. print ( "HIR STATS" , "hir-stats" ) ;
7878}
7979
80- pub fn print_ast_stats ( krate : & ast:: Crate , title : & str ) {
80+ pub fn print_ast_stats ( krate : & ast:: Crate , title : & str , prefix : & str ) {
8181 use rustc_ast:: visit:: Visitor ;
8282
8383 let mut collector =
8484 StatCollector { krate : None , nodes : FxHashMap :: default ( ) , seen : FxHashSet :: default ( ) } ;
8585 collector. visit_crate ( krate) ;
86- collector. print ( title) ;
86+ collector. print ( title, prefix ) ;
8787}
8888
8989impl < ' k > StatCollector < ' k > {
@@ -119,23 +119,26 @@ impl<'k> StatCollector<'k> {
119119 }
120120 }
121121
122- fn print ( & self , title : & str ) {
122+ fn print ( & self , title : & str , prefix : & str ) {
123123 let mut nodes: Vec < _ > = self . nodes . iter ( ) . collect ( ) ;
124124 nodes. sort_by_key ( |& ( _, ref node) | node. stats . count * node. stats . size ) ;
125125
126126 let total_size = nodes. iter ( ) . map ( |( _, node) | node. stats . count * node. stats . size ) . sum ( ) ;
127127
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) ;
132134
133135 let percent = |m, n| ( m * 100 ) as f64 / n as f64 ;
134136
135137 for ( label, node) in nodes {
136138 let size = node. stats . count * node. stats . size ;
137139 eprintln ! (
138- "{:<18}{:>10} ({:4.1}%){:>14}{:>14}" ,
140+ "{} {:<18}{:>10} ({:4.1}%){:>14}{:>14}" ,
141+ prefix,
139142 label,
140143 to_readable_str( size) ,
141144 percent( size, total_size) ,
@@ -149,7 +152,8 @@ impl<'k> StatCollector<'k> {
149152 for ( label, subnode) in subnodes {
150153 let size = subnode. count * subnode. size ;
151154 eprintln ! (
152- "- {:<18}{:>10} ({:4.1}%){:>14}" ,
155+ "{} - {:<18}{:>10} ({:4.1}%){:>14}" ,
156+ prefix,
153157 label,
154158 to_readable_str( size) ,
155159 percent( size, total_size) ,
@@ -158,8 +162,9 @@ impl<'k> StatCollector<'k> {
158162 }
159163 }
160164 }
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) ;
163168 }
164169}
165170
0 commit comments