@@ -54,9 +54,23 @@ type encode_parms = {
54
54
encode_inlined_item : encode_inlined_item
55
55
} ;
56
56
57
+ type stats = {
58
+ mut inline_bytes : uint ,
59
+ mut attr_bytes : uint ,
60
+ mut dep_bytes : uint ,
61
+ mut item_bytes : uint ,
62
+ mut index_bytes : uint ,
63
+ mut zero_bytes : uint ,
64
+ mut total_bytes : uint ,
65
+
66
+ mut n_inlines : uint
67
+ } ;
68
+
57
69
enum encode_ctxt = {
58
70
diag: span_handler,
59
71
tcx: ty:: ctxt,
72
+ buf: io:: MemBuffer ,
73
+ stats: stats,
60
74
reachable: hashmap<ast:: node_id, ( ) >,
61
75
reexports: ~[ ( ~str, def_id) ] ,
62
76
reexports2: middle:: resolve3:: ExportMap2 ,
@@ -1072,9 +1086,21 @@ fn encode_hash(ebml_w: ebml::writer, hash: ~str) {
1072
1086
}
1073
1087
1074
1088
fn encode_metadata( parms: encode_parms, crate : @crate ) -> ~[ u8] {
1089
+ let buf = io:: mem_buffer( ) ;
1090
+ let stats =
1091
+ { mut inline_bytes: 0 ,
1092
+ mut attr_bytes: 0 ,
1093
+ mut dep_bytes: 0 ,
1094
+ mut item_bytes: 0 ,
1095
+ mut index_bytes: 0 ,
1096
+ mut zero_bytes: 0 ,
1097
+ mut total_bytes: 0 ,
1098
+ mut n_inlines: 0 } ;
1075
1099
let ecx: @encode_ctxt = @encode_ctxt ( {
1076
1100
diag : parms. diag,
1077
1101
tcx : parms. tcx,
1102
+ buf : buf,
1103
+ stats : stats,
1078
1104
reachable : parms. reachable,
1079
1105
reexports : parms. reexports,
1080
1106
reexports2 : parms. reexports2,
@@ -1086,24 +1112,55 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
1086
1112
type_abbrevs : ty:: new_ty_hash( )
1087
1113
} ) ;
1088
1114
1089
- let buf = io:: mem_buffer( ) ;
1090
1115
let buf_w = io:: mem_buffer_writer( buf) ;
1091
1116
let ebml_w = ebml:: writer( buf_w) ;
1092
1117
1093
1118
encode_hash( ebml_w, ecx. link_meta. extras_hash) ;
1094
1119
1120
+ let mut i = buf. pos;
1095
1121
let crate_attrs = synthesize_crate_attrs( ecx, crate ) ;
1096
1122
encode_attributes( ebml_w, crate_attrs) ;
1123
+ ecx. stats. attr_bytes = buf. pos - i;
1097
1124
1125
+ i = buf. pos;
1098
1126
encode_crate_deps( ecx, ebml_w, ecx. cstore) ;
1127
+ ecx. stats. dep_bytes = buf. pos - i;
1099
1128
1100
1129
// Encode and index the items.
1101
1130
ebml_w. start_tag( tag_items) ;
1131
+ i = buf. pos;
1102
1132
let items_index = encode_info_for_items( ecx, ebml_w, crate ) ;
1133
+ ecx. stats. item_bytes = buf. pos - i;
1134
+
1135
+ i = buf. pos;
1103
1136
let items_buckets = create_index( items_index, hash_node_id) ;
1104
1137
encode_index( ebml_w, items_buckets, write_int) ;
1138
+ ecx. stats. index_bytes = buf. pos - i;
1105
1139
ebml_w. end_tag( ) ;
1106
1140
1141
+ ecx. stats. total_bytes = buf. pos;
1142
+
1143
+ if ( parms. tcx. sess. meta_stats( ) ) {
1144
+
1145
+ do buf. buf. borrow |v| {
1146
+ do v. each |e| {
1147
+ if e == 0 {
1148
+ ecx. stats. zero_bytes += 1 ;
1149
+ }
1150
+ true
1151
+ }
1152
+ }
1153
+
1154
+ io:: println( "metadata stats:" ) ;
1155
+ io:: println( fmt ! ( " inline bytes: %u" , ecx. stats. inline_bytes) ) ;
1156
+ io:: println( fmt ! ( " attribute bytes: %u" , ecx. stats. attr_bytes) ) ;
1157
+ io:: println( fmt ! ( " dep bytes: %u" , ecx. stats. dep_bytes) ) ;
1158
+ io:: println( fmt ! ( " item bytes: %u" , ecx. stats. item_bytes) ) ;
1159
+ io:: println( fmt ! ( " index bytes: %u" , ecx. stats. index_bytes) ) ;
1160
+ io:: println( fmt ! ( " zero bytes: %u" , ecx. stats. zero_bytes) ) ;
1161
+ io:: println( fmt ! ( " total bytes: %u" , ecx. stats. total_bytes) ) ;
1162
+ }
1163
+
1107
1164
// Pad this, since something (LLVM, presumably) is cutting off the
1108
1165
// remaining % 4 bytes.
1109
1166
buf_w. write( & [ 0u8 , 0u8 , 0u8 , 0u8 ] ) ;
0 commit comments