Skip to content
Permalink
Browse files

Label unmarked time

  • Loading branch information
Zoxc committed Jan 9, 2020
1 parent 59eb49d commit b650e91cf40500b60475c17ff289e1db761d7836
@@ -53,6 +53,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
crate_name: &str,
target_cpu: &str,
) {
let _timer = sess.timer("link_binary");
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
for &crate_type in sess.crate_types.borrow().iter() {
// Ignore executable crates if we have -Z no-codegen, as they will error.
@@ -71,9 +72,11 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
);
}

for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
check_file_is_writeable(obj, sess);
}
sess.time("link_binary_check_files_are_writeable", || {
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
check_file_is_writeable(obj, sess);
}
});

let tmpdir = TempFileBuilder::new()
.prefix("rustc")
@@ -84,6 +87,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
match crate_type {
config::CrateType::Rlib => {
let _timer = sess.timer("link_rlib");
link_rlib::<B>(
sess,
codegen_results,
@@ -118,29 +122,34 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
}

// Remove the temporary object file and metadata if we aren't saving temps
if !sess.opts.cg.save_temps {
if sess.opts.output_types.should_codegen() && !preserve_objects_for_their_debuginfo(sess) {
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
remove(sess, obj);
sess.time("link_binary_remove_temps", || {
if !sess.opts.cg.save_temps {
if sess.opts.output_types.should_codegen()
&& !preserve_objects_for_their_debuginfo(sess)
{
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
remove(sess, obj);
}
}
}
for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref()) {
remove(sess, obj);
}
if let Some(ref metadata_module) = codegen_results.metadata_module {
if let Some(ref obj) = metadata_module.object {
for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref())
{
remove(sess, obj);
}
}
if let Some(ref allocator_module) = codegen_results.allocator_module {
if let Some(ref obj) = allocator_module.object {
remove(sess, obj);
if let Some(ref metadata_module) = codegen_results.metadata_module {
if let Some(ref obj) = metadata_module.object {
remove(sess, obj);
}
}
if let Some(ref bc) = allocator_module.bytecode_compressed {
remove(sess, bc);
if let Some(ref allocator_module) = codegen_results.allocator_module {
if let Some(ref obj) = allocator_module.object {
remove(sess, obj);
}
if let Some(ref bc) = allocator_module.bytecode_compressed {
remove(sess, bc);
}
}
}
}
});
}

// The third parameter is for env vars, used on windows to set up the
@@ -479,6 +479,8 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
return work_products;
}

let _timer = sess.timer("incr_comp_copy_cgu_workproducts");

for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
let mut files = vec![];

@@ -1714,8 +1716,11 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {

impl<B: ExtraBackendMethods> OngoingCodegen<B> {
pub fn join(self, sess: &Session) -> (CodegenResults, FxHashMap<WorkProductId, WorkProduct>) {
let _timer = sess.timer("finish_ongoing_codegen");

self.shared_emitter_main.check(sess, true);
let compiled_modules = match self.future.join() {
let future = self.future;
let compiled_modules = sess.time("join_worker_thread", || match future.join() {
Ok(Ok(compiled_modules)) => compiled_modules,
Ok(Err(())) => {
sess.abort_if_errors();
@@ -1724,7 +1729,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
Err(_) => {
bug!("panic during codegen/LLVM phase");
}
};
});

sess.cgu_reuse_tracker.check_expected_reuse(sess.diagnostic());

@@ -347,6 +347,12 @@ impl<'a> TimingGuard<'a> {
pub fn none() -> TimingGuard<'a> {
TimingGuard(None)
}

#[inline(always)]
pub fn run<R>(self, f: impl FnOnce() -> R) -> R {
let _timer = self;
f()
}
}

#[must_use]
@@ -389,6 +389,7 @@ pub fn run_compiler(
})?;
} else {
// Drop AST after creating GlobalCtxt to free memory
let _timer = sess.prof.generic_activity("drop_ast");
mem::drop(queries.expansion()?.take());
}

@@ -408,11 +409,13 @@ pub fn run_compiler(
sess.code_stats.print_type_sizes();
}

let _timer = sess.timer("query_linker");
let linker = queries.linker()?;
Ok(Some(linker))
})?;

if let Some(linker) = linker {
let _timer = sess.timer("link");
linker.link()?
}

@@ -190,6 +190,8 @@ pub fn prepare_session_directory(
return;
}

let _timer = sess.timer("incr_comp_prepare_session_directory");

debug!("prepare_session_directory");

// {incr-comp-dir}/{crate-name-and-disambiguator}
@@ -306,6 +308,8 @@ pub fn finalize_session_directory(sess: &Session, svh: Svh) {
return;
}

let _timer = sess.timer("incr_comp_finalize_session_directory");

let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();

if sess.has_errors_or_delayed_span_bugs() {
@@ -102,6 +102,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
return MaybeAsync::Sync(LoadResult::Ok { data: Default::default() });
}

let _timer = sess.prof.generic_activity("incr_comp_prepare_load_dep_graph");

// Calling `sess.incr_comp_session_dir()` will panic if `sess.opts.incremental.is_none()`.
// Fortunately, we just checked that this isn't the case.
let path = dep_graph_path_from(&sess.incr_comp_session_dir());
@@ -177,11 +177,17 @@ pub fn run_compiler_in_existing_thread_pool<R>(
override_queries: config.override_queries,
};

let _sess_abort_error = OnDrop(|| {
compiler.sess.diagnostic().print_error_count(registry);
});
let r = {
let _sess_abort_error = OnDrop(|| {
compiler.sess.diagnostic().print_error_count(registry);
});

f(&compiler)
f(&compiler)
};

let prof = compiler.sess.prof.clone();
prof.generic_activity("drop_compiler").run(move || drop(compiler));
r
}

pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {
@@ -163,19 +163,22 @@ pub fn register_plugins<'a>(
)
});

let (krate, features) = rustc_expand::config::features(
krate,
&sess.parse_sess,
sess.edition(),
&sess.opts.debugging_opts.allow_features,
);
let (krate, features) = sess.time("compute_features", || {
rustc_expand::config::features(
krate,
&sess.parse_sess,
sess.edition(),
&sess.opts.debugging_opts.allow_features,
)
});
// these need to be set "early" so that expansion sees `quote` if enabled.
sess.init_features(features);

let crate_types = util::collect_crate_types(sess, &krate.attrs);
sess.crate_types.set(crate_types);

let disambiguator = util::compute_crate_disambiguator(sess);
let disambiguator =
sess.time("compute_crate_disambiguator", || util::compute_crate_disambiguator(sess));
sess.crate_disambiguator.set(disambiguator);
rustc_incremental::prepare_session_directory(sess, &crate_name, disambiguator);

@@ -611,6 +614,8 @@ pub fn prepare_outputs(
boxed_resolver: &Steal<Rc<RefCell<BoxedResolver>>>,
crate_name: &str,
) -> Result<OutputFilenames> {
let _timer = sess.timer("prepare_outputs");

// FIXME: rustdoc passes &[] instead of &krate.attrs here
let outputs = util::build_output_filenames(
&compiler.input,
@@ -721,33 +726,40 @@ pub fn create_global_ctxt<'tcx>(

let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

let codegen_backend = compiler.codegen_backend();
let mut local_providers = ty::query::Providers::default();
default_provide(&mut local_providers);
codegen_backend.provide(&mut local_providers);
let codegen_backend = sess.time("load_codegen_backend", || compiler.codegen_backend());

let mut extern_providers = local_providers;
default_provide_extern(&mut extern_providers);
codegen_backend.provide_extern(&mut extern_providers);
let (local_providers, extern_providers) = sess.time("load_codegen_backend", || {
let mut local_providers = ty::query::Providers::default();
default_provide(&mut local_providers);
codegen_backend.provide(&mut local_providers);

if let Some(callback) = compiler.override_queries {
callback(sess, &mut local_providers, &mut extern_providers);
}
let mut extern_providers = local_providers;
default_provide_extern(&mut extern_providers);
codegen_backend.provide_extern(&mut extern_providers);

let gcx = global_ctxt.init_locking(|| {
TyCtxt::create_global_ctxt(
sess,
lint_store,
local_providers,
extern_providers,
&all_arenas,
arena,
resolver_outputs,
hir_map,
query_result_on_disk_cache,
&crate_name,
&outputs,
)
if let Some(callback) = compiler.override_queries {
callback(sess, &mut local_providers, &mut extern_providers);
}

(local_providers, extern_providers)
});

let gcx = sess.time("setup_global_ctxt", || {
global_ctxt.init_locking(|| {
TyCtxt::create_global_ctxt(
sess,
lint_store,
local_providers,
extern_providers,
&all_arenas,
arena,
resolver_outputs,
hir_map,
query_result_on_disk_cache,
&crate_name,
&outputs,
)
})
});

// Do some initialization of the DepGraph that can only be done with the tcx available.
@@ -158,6 +158,7 @@ impl<'tcx> Queries<'tcx> {
Ok(match self.compiler.crate_name {
Some(ref crate_name) => crate_name.clone(),
None => {
let _timer = self.session().timer("crate_name");
let parse_result = self.parse()?;
let krate = parse_result.peek();
rustc_codegen_utils::link::find_crate_name(
@@ -176,6 +177,7 @@ impl<'tcx> Queries<'tcx> {
self.expansion.compute(|| {
let crate_name = self.crate_name()?.peek().clone();
let (krate, lint_store) = self.register_plugins()?.take();
let _timer = self.session().timer("configure_and_expand");
passes::configure_and_expand(
self.session().clone(),
lint_store.clone(),
@@ -256,6 +258,7 @@ impl<'tcx> Queries<'tcx> {
let lint_store = self.expansion()?.peek().2.clone();
let hir = self.lower_to_hir()?.peek();
let (ref hir_forest, ref resolver_outputs) = &*hir;
let _timer = self.session().timer("create_global_ctxt");
Ok(passes::create_global_ctxt(
self.compiler,
lint_store,
@@ -312,14 +315,19 @@ pub struct Linker {

impl Linker {
pub fn link(self) -> Result<()> {
self.codegen_backend
let r = self
.codegen_backend
.join_codegen_and_link(
self.ongoing_codegen,
&self.sess,
&self.dep_graph,
&self.prepare_outputs,
)
.map_err(|_| ErrorReported)
.map_err(|_| ErrorReported);
let prof = self.sess.prof.clone();
let dep_graph = self.dep_graph;
prof.generic_activity("drop_dep_graph").run(move || drop(dep_graph));
r
}
}

@@ -328,6 +336,7 @@ impl Compiler {
where
F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T,
{
let mut _timer = None;
let queries = Queries::new(&self);
let ret = f(&queries);

@@ -337,6 +346,8 @@ impl Compiler {
}
}

_timer = Some(self.session().timer("free_global_ctxt"));

ret
}

0 comments on commit b650e91

Please sign in to comment.
You can’t perform that action at this time.