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

Add some missing timers #68043

Merged
merged 2 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn lower_crate<'a, 'hir>(
// incr. comp. yet.
dep_graph.assert_ignored();

let _prof_timer = sess.prof.generic_activity("hir_lowering");
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");

LoweringContext {
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),
Expand Down
49 changes: 29 additions & 20 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];

Expand Down Expand Up @@ -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();
Expand All @@ -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());

Expand Down
6 changes: 6 additions & 0 deletions src/librustc_data_structures/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -413,6 +414,7 @@ pub fn run_compiler(
})?;

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

Expand Down
4 changes: 4 additions & 0 deletions src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_incremental/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 10 additions & 4 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 18 additions & 14 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,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,
Expand Down Expand Up @@ -734,20 +736,22 @@ pub fn create_global_ctxt<'tcx>(
callback(sess, &mut local_providers, &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,
)
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.
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,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(),
Expand Down Expand Up @@ -256,6 +257,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,
Expand Down Expand Up @@ -312,14 +314,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
}
}

Expand All @@ -328,6 +335,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);

Expand All @@ -337,6 +345,8 @@ impl Compiler {
}
}

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

ret
}

Expand Down