Add some counters to metadata.
This commit is contained in:
parent
9fafb63d5e
commit
88e0476bd0
2 changed files with 62 additions and 2 deletions
|
|
@ -42,6 +42,7 @@ const borrowck_note_loan: uint = 4096;
|
|||
const no_landing_pads: uint = 8192;
|
||||
const debug_llvm: uint = 16384;
|
||||
const count_type_sizes: uint = 32768;
|
||||
const meta_stats: uint = 65536;
|
||||
|
||||
fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
|
||||
~[(~"ppregions", ~"prettyprint regions with \
|
||||
|
|
@ -66,7 +67,8 @@ fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
|
|||
no_landing_pads),
|
||||
(~"debug-llvm", ~"enable debug output from LLVM", debug_llvm),
|
||||
(~"count-type-sizes", ~"count the sizes of aggregate types",
|
||||
count_type_sizes)
|
||||
count_type_sizes),
|
||||
(~"meta-stats", ~"gather metadata statistics", meta_stats)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -198,6 +200,7 @@ impl session {
|
|||
fn count_type_sizes() -> bool { self.debugging_opt(count_type_sizes) }
|
||||
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
|
||||
fn trans_stats() -> bool { self.debugging_opt(trans_stats) }
|
||||
fn meta_stats() -> bool { self.debugging_opt(meta_stats) }
|
||||
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
|
||||
fn no_verify() -> bool { self.debugging_opt(no_verify) }
|
||||
fn trace() -> bool { self.debugging_opt(trace) }
|
||||
|
|
|
|||
|
|
@ -54,9 +54,23 @@ type encode_parms = {
|
|||
encode_inlined_item: encode_inlined_item
|
||||
};
|
||||
|
||||
type stats = {
|
||||
mut inline_bytes: uint,
|
||||
mut attr_bytes: uint,
|
||||
mut dep_bytes: uint,
|
||||
mut item_bytes: uint,
|
||||
mut index_bytes: uint,
|
||||
mut zero_bytes: uint,
|
||||
mut total_bytes: uint,
|
||||
|
||||
mut n_inlines: uint
|
||||
};
|
||||
|
||||
enum encode_ctxt = {
|
||||
diag: span_handler,
|
||||
tcx: ty::ctxt,
|
||||
buf: io::MemBuffer,
|
||||
stats: stats,
|
||||
reachable: hashmap<ast::node_id, ()>,
|
||||
reexports: ~[(~str, def_id)],
|
||||
reexports2: middle::resolve3::ExportMap2,
|
||||
|
|
@ -1072,9 +1086,21 @@ fn encode_hash(ebml_w: ebml::writer, hash: ~str) {
|
|||
}
|
||||
|
||||
fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
||||
let buf = io::mem_buffer();
|
||||
let stats =
|
||||
{mut inline_bytes: 0,
|
||||
mut attr_bytes: 0,
|
||||
mut dep_bytes: 0,
|
||||
mut item_bytes: 0,
|
||||
mut index_bytes: 0,
|
||||
mut zero_bytes: 0,
|
||||
mut total_bytes: 0,
|
||||
mut n_inlines: 0};
|
||||
let ecx: @encode_ctxt = @encode_ctxt({
|
||||
diag: parms.diag,
|
||||
tcx: parms.tcx,
|
||||
buf: buf,
|
||||
stats: stats,
|
||||
reachable: parms.reachable,
|
||||
reexports: parms.reexports,
|
||||
reexports2: parms.reexports2,
|
||||
|
|
@ -1086,24 +1112,55 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||
type_abbrevs: ty::new_ty_hash()
|
||||
});
|
||||
|
||||
let buf = io::mem_buffer();
|
||||
let buf_w = io::mem_buffer_writer(buf);
|
||||
let ebml_w = ebml::writer(buf_w);
|
||||
|
||||
encode_hash(ebml_w, ecx.link_meta.extras_hash);
|
||||
|
||||
let mut i = buf.pos;
|
||||
let crate_attrs = synthesize_crate_attrs(ecx, crate);
|
||||
encode_attributes(ebml_w, crate_attrs);
|
||||
ecx.stats.attr_bytes = buf.pos - i;
|
||||
|
||||
i = buf.pos;
|
||||
encode_crate_deps(ecx, ebml_w, ecx.cstore);
|
||||
ecx.stats.dep_bytes = buf.pos - i;
|
||||
|
||||
// Encode and index the items.
|
||||
ebml_w.start_tag(tag_items);
|
||||
i = buf.pos;
|
||||
let items_index = encode_info_for_items(ecx, ebml_w, crate);
|
||||
ecx.stats.item_bytes = buf.pos - i;
|
||||
|
||||
i = buf.pos;
|
||||
let items_buckets = create_index(items_index, hash_node_id);
|
||||
encode_index(ebml_w, items_buckets, write_int);
|
||||
ecx.stats.index_bytes = buf.pos - i;
|
||||
ebml_w.end_tag();
|
||||
|
||||
ecx.stats.total_bytes = buf.pos;
|
||||
|
||||
if (parms.tcx.sess.meta_stats()) {
|
||||
|
||||
do buf.buf.borrow |v| {
|
||||
do v.each |e| {
|
||||
if e == 0 {
|
||||
ecx.stats.zero_bytes += 1;
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
io::println("metadata stats:");
|
||||
io::println(fmt!(" inline bytes: %u", ecx.stats.inline_bytes));
|
||||
io::println(fmt!(" attribute bytes: %u", ecx.stats.attr_bytes));
|
||||
io::println(fmt!(" dep bytes: %u", ecx.stats.dep_bytes));
|
||||
io::println(fmt!(" item bytes: %u", ecx.stats.item_bytes));
|
||||
io::println(fmt!(" index bytes: %u", ecx.stats.index_bytes));
|
||||
io::println(fmt!(" zero bytes: %u", ecx.stats.zero_bytes));
|
||||
io::println(fmt!(" total bytes: %u", ecx.stats.total_bytes));
|
||||
}
|
||||
|
||||
// Pad this, since something (LLVM, presumably) is cutting off the
|
||||
// remaining % 4 bytes.
|
||||
buf_w.write(&[0u8, 0u8, 0u8, 0u8]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue