Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crater: closure size profile build #87066

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions compiler/rustc_mir/src/monomorphize/util.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::ty::{self, ClosureSizeProfileData, Instance, TyCtxt};
use std::fs::OpenOptions;
use std::io::prelude::*;

/// For a given closure, writes out the data for the profiling the impact of RFC 2229 on
/// closure size into a CSV.
///
/// During the same compile all closures dump the information in the same file
/// "closure_profile_XXXXX.csv", which is created in the directory where the compiler is invoked.
crate fn dump_closure_profile(tcx: TyCtxt<'tcx>, closure_instance: Instance<'tcx>) {
let mut file = if let Ok(file) = OpenOptions::new()
.create(true)
.append(true)
.open(&format!("closure_profile_{}.csv", std::process::id()))
{
file
} else {
eprintln!("Cound't open file for writing closure profile");
return;
};

let closure_def_id = closure_instance.def_id();
let typeck_results = tcx.typeck(closure_def_id.expect_local());

let crate_name = tcx.crate_name(LOCAL_CRATE);

if typeck_results.closure_size_eval.contains_key(&closure_def_id) {
let param_env = ty::ParamEnv::reveal_all();

Expand Down Expand Up @@ -49,25 +40,10 @@ crate fn dump_closure_profile(tcx: TyCtxt<'tcx>, closure_instance: Instance<'tcx
.map(|l| format!("{:?}", l.size.bytes()))
.unwrap_or_else(|e| format!("Failed {:?}", e));

let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
let closure_span = tcx.hir().span(closure_hir_id);
let src_file = tcx.sess.source_map().span_to_filename(closure_span);
let line_nos = tcx
.sess
.source_map()
.span_to_lines(closure_span)
.map(|l| format!("{:?} {:?}", l.lines.first(), l.lines.last()))
.unwrap_or_else(|e| format!("{:?}", e));
let mut hasher = StableHasher::new();
closure_instance.hash_stable(&mut tcx.create_stable_hashing_context(), &mut hasher);
let hash = hasher.finalize();

if let Err(e) = writeln!(
file,
"{}, {}, {}, {:?}",
old_size,
new_size,
src_file.prefer_local(),
line_nos
) {
eprintln!("Error writting to file {}", e.to_string())
}
eprintln!("SG_CR_Eslkdjf: {}, {:x?}, {}, {}", crate_name, hash, old_size, new_size);
}
}