1
Fork 0

rustc: de-@ stats.

This commit is contained in:
Eduard Burtescu 2014-04-22 03:25:56 +03:00
parent 938eaaa304
commit 9dc99c89d3
3 changed files with 70 additions and 76 deletions

View file

@ -27,7 +27,7 @@ use util::nodemap::{NodeMap, NodeSet};
use serialize::Encodable; use serialize::Encodable;
use std::cast; use std::cast;
use std::cell::{Cell, RefCell}; use std::cell::RefCell;
use std::hash; use std::hash;
use std::hash::Hash; use std::hash::Hash;
use std::io::MemWriter; use std::io::MemWriter;
@ -76,26 +76,9 @@ pub struct EncodeParams<'a> {
pub encode_inlined_item: EncodeInlinedItem<'a>, pub encode_inlined_item: EncodeInlinedItem<'a>,
} }
pub struct Stats {
inline_bytes: Cell<u64>,
attr_bytes: Cell<u64>,
dep_bytes: Cell<u64>,
lang_item_bytes: Cell<u64>,
native_lib_bytes: Cell<u64>,
macro_registrar_fn_bytes: Cell<u64>,
macro_defs_bytes: Cell<u64>,
impl_bytes: Cell<u64>,
misc_bytes: Cell<u64>,
item_bytes: Cell<u64>,
index_bytes: Cell<u64>,
zero_bytes: Cell<u64>,
total_bytes: Cell<u64>,
}
pub struct EncodeContext<'a> { pub struct EncodeContext<'a> {
pub diag: &'a SpanHandler, pub diag: &'a SpanHandler,
pub tcx: &'a ty::ctxt, pub tcx: &'a ty::ctxt,
pub stats: @Stats,
pub reexports2: &'a middle::resolve::ExportMap2, pub reexports2: &'a middle::resolve::ExportMap2,
pub item_symbols: &'a RefCell<NodeMap<~str>>, pub item_symbols: &'a RefCell<NodeMap<~str>>,
pub non_inlineable_statics: &'a RefCell<NodeSet>, pub non_inlineable_statics: &'a RefCell<NodeSet>,
@ -1701,20 +1684,33 @@ pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec<u8> {
} }
fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) { fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) {
let stats = Stats { struct Stats {
inline_bytes: Cell::new(0), attr_bytes: u64,
attr_bytes: Cell::new(0), dep_bytes: u64,
dep_bytes: Cell::new(0), lang_item_bytes: u64,
lang_item_bytes: Cell::new(0), native_lib_bytes: u64,
native_lib_bytes: Cell::new(0), macro_registrar_fn_bytes: u64,
macro_registrar_fn_bytes: Cell::new(0), macro_defs_bytes: u64,
macro_defs_bytes: Cell::new(0), impl_bytes: u64,
impl_bytes: Cell::new(0), misc_bytes: u64,
misc_bytes: Cell::new(0), item_bytes: u64,
item_bytes: Cell::new(0), index_bytes: u64,
index_bytes: Cell::new(0), zero_bytes: u64,
zero_bytes: Cell::new(0), total_bytes: u64,
total_bytes: Cell::new(0), }
let mut stats = Stats {
attr_bytes: 0,
dep_bytes: 0,
lang_item_bytes: 0,
native_lib_bytes: 0,
macro_registrar_fn_bytes: 0,
macro_defs_bytes: 0,
impl_bytes: 0,
misc_bytes: 0,
item_bytes: 0,
index_bytes: 0,
zero_bytes: 0,
total_bytes: 0,
}; };
let EncodeParams { let EncodeParams {
item_symbols, item_symbols,
@ -1730,7 +1726,6 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
let ecx = EncodeContext { let ecx = EncodeContext {
diag: diag, diag: diag,
tcx: tcx, tcx: tcx,
stats: @stats,
reexports2: reexports2, reexports2: reexports2,
item_symbols: item_symbols, item_symbols: item_symbols,
non_inlineable_statics: non_inlineable_statics, non_inlineable_statics: non_inlineable_statics,
@ -1748,76 +1743,75 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate)
let mut i = ebml_w.writer.tell().unwrap(); let mut i = ebml_w.writer.tell().unwrap();
let crate_attrs = synthesize_crate_attrs(&ecx, krate); let crate_attrs = synthesize_crate_attrs(&ecx, krate);
encode_attributes(&mut ebml_w, crate_attrs.as_slice()); encode_attributes(&mut ebml_w, crate_attrs.as_slice());
ecx.stats.attr_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.attr_bytes = ebml_w.writer.tell().unwrap() - i;
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_crate_deps(&mut ebml_w, ecx.cstore); encode_crate_deps(&mut ebml_w, ecx.cstore);
ecx.stats.dep_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.dep_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode the language items. // Encode the language items.
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_lang_items(&ecx, &mut ebml_w); encode_lang_items(&ecx, &mut ebml_w);
ecx.stats.lang_item_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.lang_item_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode the native libraries used // Encode the native libraries used
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_native_libraries(&ecx, &mut ebml_w); encode_native_libraries(&ecx, &mut ebml_w);
ecx.stats.native_lib_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.native_lib_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode the macro registrar function // Encode the macro registrar function
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_macro_registrar_fn(&ecx, &mut ebml_w); encode_macro_registrar_fn(&ecx, &mut ebml_w);
ecx.stats.macro_registrar_fn_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.macro_registrar_fn_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode macro definitions // Encode macro definitions
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_macro_defs(&ecx, krate, &mut ebml_w); encode_macro_defs(&ecx, krate, &mut ebml_w);
ecx.stats.macro_defs_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.macro_defs_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode the def IDs of impls, for coherence checking. // Encode the def IDs of impls, for coherence checking.
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_impls(&ecx, krate, &mut ebml_w); encode_impls(&ecx, krate, &mut ebml_w);
ecx.stats.impl_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.impl_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode miscellaneous info. // Encode miscellaneous info.
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_misc_info(&ecx, krate, &mut ebml_w); encode_misc_info(&ecx, krate, &mut ebml_w);
ecx.stats.misc_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.misc_bytes = ebml_w.writer.tell().unwrap() - i;
// Encode and index the items. // Encode and index the items.
ebml_w.start_tag(tag_items); ebml_w.start_tag(tag_items);
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
let items_index = encode_info_for_items(&ecx, &mut ebml_w, krate); let items_index = encode_info_for_items(&ecx, &mut ebml_w, krate);
ecx.stats.item_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.item_bytes = ebml_w.writer.tell().unwrap() - i;
i = ebml_w.writer.tell().unwrap(); i = ebml_w.writer.tell().unwrap();
encode_index(&mut ebml_w, items_index, write_i64); encode_index(&mut ebml_w, items_index, write_i64);
ecx.stats.index_bytes.set(ebml_w.writer.tell().unwrap() - i); stats.index_bytes = ebml_w.writer.tell().unwrap() - i;
ebml_w.end_tag(); ebml_w.end_tag();
ecx.stats.total_bytes.set(ebml_w.writer.tell().unwrap()); stats.total_bytes = ebml_w.writer.tell().unwrap();
if tcx.sess.meta_stats() { if tcx.sess.meta_stats() {
for e in ebml_w.writer.get_ref().iter() { for e in ebml_w.writer.get_ref().iter() {
if *e == 0 { if *e == 0 {
ecx.stats.zero_bytes.set(ecx.stats.zero_bytes.get() + 1); stats.zero_bytes += 1;
} }
} }
println!("metadata stats:"); println!("metadata stats:");
println!(" inline bytes: {}", ecx.stats.inline_bytes.get()); println!(" attribute bytes: {}", stats.attr_bytes);
println!(" attribute bytes: {}", ecx.stats.attr_bytes.get()); println!(" dep bytes: {}", stats.dep_bytes);
println!(" dep bytes: {}", ecx.stats.dep_bytes.get()); println!(" lang item bytes: {}", stats.lang_item_bytes);
println!(" lang item bytes: {}", ecx.stats.lang_item_bytes.get()); println!(" native bytes: {}", stats.native_lib_bytes);
println!(" native bytes: {}", ecx.stats.native_lib_bytes.get()); println!("macro registrar bytes: {}", stats.macro_registrar_fn_bytes);
println!("macro registrar bytes: {}", ecx.stats.macro_registrar_fn_bytes.get()); println!(" macro def bytes: {}", stats.macro_defs_bytes);
println!(" macro def bytes: {}", ecx.stats.macro_defs_bytes.get()); println!(" impl bytes: {}", stats.impl_bytes);
println!(" impl bytes: {}", ecx.stats.impl_bytes.get()); println!(" misc bytes: {}", stats.misc_bytes);
println!(" misc bytes: {}", ecx.stats.misc_bytes.get()); println!(" item bytes: {}", stats.item_bytes);
println!(" item bytes: {}", ecx.stats.item_bytes.get()); println!(" index bytes: {}", stats.index_bytes);
println!(" index bytes: {}", ecx.stats.index_bytes.get()); println!(" zero bytes: {}", stats.zero_bytes);
println!(" zero bytes: {}", ecx.stats.zero_bytes.get()); println!(" total bytes: {}", stats.total_bytes);
println!(" total bytes: {}", ecx.stats.total_bytes.get());
} }
} }

View file

@ -154,21 +154,6 @@ pub fn expr_info(expr: &ast::Expr) -> NodeInfo {
NodeInfo { id: expr.id, span: expr.span } NodeInfo { id: expr.id, span: expr.span }
} }
pub struct Stats {
pub n_static_tydescs: Cell<uint>,
pub n_glues_created: Cell<uint>,
pub n_null_glues: Cell<uint>,
pub n_real_glues: Cell<uint>,
pub n_fns: Cell<uint>,
pub n_monos: Cell<uint>,
pub n_inlines: Cell<uint>,
pub n_closures: Cell<uint>,
pub n_llvm_insns: Cell<uint>,
pub llvm_insns: RefCell<HashMap<~str, uint>>,
// (ident, time-in-ms, llvm-instructions)
pub fn_stats: RefCell<Vec<(~str, uint, uint)> >,
}
pub struct BuilderRef_res { pub struct BuilderRef_res {
pub b: BuilderRef, pub b: BuilderRef,
} }

View file

@ -20,7 +20,7 @@ use middle::resolve;
use middle::trans::adt; use middle::trans::adt;
use middle::trans::base; use middle::trans::base;
use middle::trans::builder::Builder; use middle::trans::builder::Builder;
use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats}; use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res};
use middle::trans::debuginfo; use middle::trans::debuginfo;
use middle::trans::monomorphize::MonoId; use middle::trans::monomorphize::MonoId;
use middle::trans::type_::Type; use middle::trans::type_::Type;
@ -36,6 +36,21 @@ use collections::{HashMap, HashSet};
use syntax::ast; use syntax::ast;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
pub struct Stats {
pub n_static_tydescs: Cell<uint>,
pub n_glues_created: Cell<uint>,
pub n_null_glues: Cell<uint>,
pub n_real_glues: Cell<uint>,
pub n_fns: Cell<uint>,
pub n_monos: Cell<uint>,
pub n_inlines: Cell<uint>,
pub n_closures: Cell<uint>,
pub n_llvm_insns: Cell<uint>,
pub llvm_insns: RefCell<HashMap<~str, uint>>,
// (ident, time-in-ms, llvm-instructions)
pub fn_stats: RefCell<Vec<(~str, uint, uint)> >,
}
pub struct CrateContext { pub struct CrateContext {
pub llmod: ModuleRef, pub llmod: ModuleRef,
pub llcx: ContextRef, pub llcx: ContextRef,
@ -99,7 +114,7 @@ pub struct CrateContext {
pub all_llvm_symbols: RefCell<HashSet<~str>>, pub all_llvm_symbols: RefCell<HashSet<~str>>,
pub tcx: ty::ctxt, pub tcx: ty::ctxt,
pub maps: astencode::Maps, pub maps: astencode::Maps,
pub stats: @Stats, pub stats: Stats,
pub int_type: Type, pub int_type: Type,
pub opaque_vec_type: Type, pub opaque_vec_type: Type,
pub builder: BuilderRef_res, pub builder: BuilderRef_res,
@ -181,7 +196,7 @@ impl CrateContext {
all_llvm_symbols: RefCell::new(HashSet::new()), all_llvm_symbols: RefCell::new(HashSet::new()),
tcx: tcx, tcx: tcx,
maps: maps, maps: maps,
stats: @Stats { stats: Stats {
n_static_tydescs: Cell::new(0u), n_static_tydescs: Cell::new(0u),
n_glues_created: Cell::new(0u), n_glues_created: Cell::new(0u),
n_null_glues: Cell::new(0u), n_null_glues: Cell::new(0u),