Skip to content

Commit 8c0c5c7

Browse files
authored
Rollup merge of rust-lang#68043 - Zoxc:missing-timers, r=wesleywiser
Add some missing timers Based on rust-lang#67988 r? @wesleywiser
2 parents 9634e1f + 5918c18 commit 8c0c5c7

File tree

10 files changed

+91
-43
lines changed

10 files changed

+91
-43
lines changed

src/librustc_ast_lowering/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn lower_crate<'a, 'hir>(
268268
// incr. comp. yet.
269269
dep_graph.assert_ignored();
270270

271-
let _prof_timer = sess.prof.generic_activity("hir_lowering");
271+
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");
272272

273273
LoweringContext {
274274
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),

src/librustc_codegen_ssa/back/link.rs

+29-20
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
5353
crate_name: &str,
5454
target_cpu: &str,
5555
) {
56+
let _timer = sess.timer("link_binary");
5657
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
5758
for &crate_type in sess.crate_types.borrow().iter() {
5859
// 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>>(
7172
);
7273
}
7374

74-
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
75-
check_file_is_writeable(obj, sess);
76-
}
75+
sess.time("link_binary_check_files_are_writeable", || {
76+
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
77+
check_file_is_writeable(obj, sess);
78+
}
79+
});
7780

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

120124
// Remove the temporary object file and metadata if we aren't saving temps
121-
if !sess.opts.cg.save_temps {
122-
if sess.opts.output_types.should_codegen() && !preserve_objects_for_their_debuginfo(sess) {
123-
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
124-
remove(sess, obj);
125+
sess.time("link_binary_remove_temps", || {
126+
if !sess.opts.cg.save_temps {
127+
if sess.opts.output_types.should_codegen()
128+
&& !preserve_objects_for_their_debuginfo(sess)
129+
{
130+
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
131+
remove(sess, obj);
132+
}
125133
}
126-
}
127-
for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref()) {
128-
remove(sess, obj);
129-
}
130-
if let Some(ref metadata_module) = codegen_results.metadata_module {
131-
if let Some(ref obj) = metadata_module.object {
134+
for obj in codegen_results.modules.iter().filter_map(|m| m.bytecode_compressed.as_ref())
135+
{
132136
remove(sess, obj);
133137
}
134-
}
135-
if let Some(ref allocator_module) = codegen_results.allocator_module {
136-
if let Some(ref obj) = allocator_module.object {
137-
remove(sess, obj);
138+
if let Some(ref metadata_module) = codegen_results.metadata_module {
139+
if let Some(ref obj) = metadata_module.object {
140+
remove(sess, obj);
141+
}
138142
}
139-
if let Some(ref bc) = allocator_module.bytecode_compressed {
140-
remove(sess, bc);
143+
if let Some(ref allocator_module) = codegen_results.allocator_module {
144+
if let Some(ref obj) = allocator_module.object {
145+
remove(sess, obj);
146+
}
147+
if let Some(ref bc) = allocator_module.bytecode_compressed {
148+
remove(sess, bc);
149+
}
141150
}
142151
}
143-
}
152+
});
144153
}
145154

146155
// The third parameter is for env vars, used on windows to set up the

src/librustc_codegen_ssa/back/write.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
479479
return work_products;
480480
}
481481

482+
let _timer = sess.timer("incr_comp_copy_cgu_workproducts");
483+
482484
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
483485
let mut files = vec![];
484486

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

17151717
impl<B: ExtraBackendMethods> OngoingCodegen<B> {
17161718
pub fn join(self, sess: &Session) -> (CodegenResults, FxHashMap<WorkProductId, WorkProduct>) {
1719+
let _timer = sess.timer("finish_ongoing_codegen");
1720+
17171721
self.shared_emitter_main.check(sess, true);
1718-
let compiled_modules = match self.future.join() {
1722+
let future = self.future;
1723+
let compiled_modules = sess.time("join_worker_thread", || match future.join() {
17191724
Ok(Ok(compiled_modules)) => compiled_modules,
17201725
Ok(Err(())) => {
17211726
sess.abort_if_errors();
@@ -1724,7 +1729,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
17241729
Err(_) => {
17251730
bug!("panic during codegen/LLVM phase");
17261731
}
1727-
};
1732+
});
17281733

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

src/librustc_data_structures/profiling.rs

+6
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ impl<'a> TimingGuard<'a> {
495495
pub fn none() -> TimingGuard<'a> {
496496
TimingGuard(None)
497497
}
498+
499+
#[inline(always)]
500+
pub fn run<R>(self, f: impl FnOnce() -> R) -> R {
501+
let _timer = self;
502+
f()
503+
}
498504
}
499505

500506
#[must_use]

src/librustc_driver/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ pub fn run_compiler(
389389
})?;
390390
} else {
391391
// Drop AST after creating GlobalCtxt to free memory
392+
let _timer = sess.prof.generic_activity("drop_ast");
392393
mem::drop(queries.expansion()?.take());
393394
}
394395

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

415416
if let Some(linker) = linker {
417+
let _timer = sess.timer("link");
416418
linker.link()?
417419
}
418420

src/librustc_incremental/persist/fs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ pub fn prepare_session_directory(
190190
return;
191191
}
192192

193+
let _timer = sess.timer("incr_comp_prepare_session_directory");
194+
193195
debug!("prepare_session_directory");
194196

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

311+
let _timer = sess.timer("incr_comp_finalize_session_directory");
312+
309313
let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
310314

311315
if sess.has_errors_or_delayed_span_bugs() {

src/librustc_incremental/persist/load.rs

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
102102
return MaybeAsync::Sync(LoadResult::Ok { data: Default::default() });
103103
}
104104

105+
let _timer = sess.prof.generic_activity("incr_comp_prepare_load_dep_graph");
106+
105107
// Calling `sess.incr_comp_session_dir()` will panic if `sess.opts.incremental.is_none()`.
106108
// Fortunately, we just checked that this isn't the case.
107109
let path = dep_graph_path_from(&sess.incr_comp_session_dir());

src/librustc_interface/interface.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,17 @@ pub fn run_compiler_in_existing_thread_pool<R>(
177177
override_queries: config.override_queries,
178178
};
179179

180-
let _sess_abort_error = OnDrop(|| {
181-
compiler.sess.diagnostic().print_error_count(registry);
182-
});
180+
let r = {
181+
let _sess_abort_error = OnDrop(|| {
182+
compiler.sess.diagnostic().print_error_count(registry);
183+
});
183184

184-
f(&compiler)
185+
f(&compiler)
186+
};
187+
188+
let prof = compiler.sess.prof.clone();
189+
prof.generic_activity("drop_compiler").run(move || drop(compiler));
190+
r
185191
}
186192

187193
pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {

src/librustc_interface/passes.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ pub fn prepare_outputs(
610610
boxed_resolver: &Steal<Rc<RefCell<BoxedResolver>>>,
611611
crate_name: &str,
612612
) -> Result<OutputFilenames> {
613+
let _timer = sess.timer("prepare_outputs");
614+
613615
// FIXME: rustdoc passes &[] instead of &krate.attrs here
614616
let outputs = util::build_output_filenames(
615617
&compiler.input,
@@ -733,20 +735,22 @@ pub fn create_global_ctxt<'tcx>(
733735
callback(sess, &mut local_providers, &mut extern_providers);
734736
}
735737

736-
let gcx = global_ctxt.init_locking(|| {
737-
TyCtxt::create_global_ctxt(
738-
sess,
739-
lint_store,
740-
local_providers,
741-
extern_providers,
742-
&all_arenas,
743-
arena,
744-
resolver_outputs,
745-
hir_map,
746-
query_result_on_disk_cache,
747-
&crate_name,
748-
&outputs,
749-
)
738+
let gcx = sess.time("setup_global_ctxt", || {
739+
global_ctxt.init_locking(|| {
740+
TyCtxt::create_global_ctxt(
741+
sess,
742+
lint_store,
743+
local_providers,
744+
extern_providers,
745+
&all_arenas,
746+
arena,
747+
resolver_outputs,
748+
hir_map,
749+
query_result_on_disk_cache,
750+
&crate_name,
751+
&outputs,
752+
)
753+
})
750754
});
751755

752756
// Do some initialization of the DepGraph that can only be done with the tcx available.

src/librustc_interface/queries.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl<'tcx> Queries<'tcx> {
176176
self.expansion.compute(|| {
177177
let crate_name = self.crate_name()?.peek().clone();
178178
let (krate, lint_store) = self.register_plugins()?.take();
179+
let _timer = self.session().timer("configure_and_expand");
179180
passes::configure_and_expand(
180181
self.session().clone(),
181182
lint_store.clone(),
@@ -256,6 +257,7 @@ impl<'tcx> Queries<'tcx> {
256257
let lint_store = self.expansion()?.peek().2.clone();
257258
let hir = self.lower_to_hir()?.peek();
258259
let (ref hir_forest, ref resolver_outputs) = &*hir;
260+
let _timer = self.session().timer("create_global_ctxt");
259261
Ok(passes::create_global_ctxt(
260262
self.compiler,
261263
lint_store,
@@ -312,14 +314,19 @@ pub struct Linker {
312314

313315
impl Linker {
314316
pub fn link(self) -> Result<()> {
315-
self.codegen_backend
317+
let r = self
318+
.codegen_backend
316319
.join_codegen_and_link(
317320
self.ongoing_codegen,
318321
&self.sess,
319322
&self.dep_graph,
320323
&self.prepare_outputs,
321324
)
322-
.map_err(|_| ErrorReported)
325+
.map_err(|_| ErrorReported);
326+
let prof = self.sess.prof.clone();
327+
let dep_graph = self.dep_graph;
328+
prof.generic_activity("drop_dep_graph").run(move || drop(dep_graph));
329+
r
323330
}
324331
}
325332

@@ -328,6 +335,7 @@ impl Compiler {
328335
where
329336
F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T,
330337
{
338+
let mut _timer = None;
331339
let queries = Queries::new(&self);
332340
let ret = f(&queries);
333341

@@ -337,6 +345,8 @@ impl Compiler {
337345
}
338346
}
339347

348+
_timer = Some(self.session().timer("free_global_ctxt"));
349+
340350
ret
341351
}
342352

0 commit comments

Comments
 (0)