Skip to content

Commit d942622

Browse files
Self-Profiling: Make names of existing events more consistent and use new API.
1 parent b0b073c commit d942622

File tree

11 files changed

+122
-158
lines changed

11 files changed

+122
-158
lines changed

src/librustc/ty/query/plumbing.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
112112
let mut lock = cache.get_shard_by_value(key).lock();
113113
if let Some(value) = lock.results.get(key) {
114114
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
115-
tcx.sess.profiler(|p| p.record_query_hit(Q::NAME));
115+
tcx.prof.query_cache_hit(Q::NAME);
116116
let result = (value.value.clone(), value.index);
117117
#[cfg(debug_assertions)]
118118
{
@@ -128,7 +128,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
128128
// in another thread has completed. Record how long we wait in the
129129
// self-profiler.
130130
#[cfg(parallel_compiler)]
131-
tcx.sess.profiler(|p| p.query_blocked_start(Q::NAME));
131+
tcx.prof.query_blocked_start(Q::NAME);
132132

133133
job.clone()
134134
},
@@ -170,7 +170,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
170170
#[cfg(parallel_compiler)]
171171
{
172172
let result = job.r#await(tcx, span);
173-
tcx.sess.profiler(|p| p.query_blocked_end(Q::NAME));
173+
tcx.prof.query_blocked_end(Q::NAME);
174174

175175
if let Err(cycle) = result {
176176
return TryGetJob::Cycle(Q::handle_cycle_error(tcx, cycle));
@@ -382,8 +382,9 @@ impl<'tcx> TyCtxt<'tcx> {
382382
}
383383

384384
if Q::ANON {
385+
385386
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
386-
self.sess.profiler(|p| p.start_query(Q::NAME));
387+
let prof_timer = self.prof.query_provider(Q::NAME);
387388

388389
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
389390
self.start_query(job.job.clone(), diagnostics, |tcx| {
@@ -393,7 +394,7 @@ impl<'tcx> TyCtxt<'tcx> {
393394
})
394395
});
395396

396-
self.sess.profiler(|p| p.end_query(Q::NAME));
397+
drop(prof_timer);
397398
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
398399

399400
self.dep_graph.read_index(dep_node_index);
@@ -451,9 +452,8 @@ impl<'tcx> TyCtxt<'tcx> {
451452
// First we try to load the result from the on-disk cache.
452453
let result = if Q::cache_on_disk(self, key.clone(), None) &&
453454
self.sess.opts.debugging_opts.incremental_queries {
454-
self.sess.profiler(|p| p.incremental_load_result_start(Q::NAME));
455+
let _prof_timer = self.prof.incr_cache_loading(Q::NAME);
455456
let result = Q::try_load_from_disk(self, prev_dep_node_index);
456-
self.sess.profiler(|p| p.incremental_load_result_end(Q::NAME));
457457

458458
// We always expect to find a cached result for things that
459459
// can be forced from `DepNode`.
@@ -469,21 +469,17 @@ impl<'tcx> TyCtxt<'tcx> {
469469

470470
let result = if let Some(result) = result {
471471
profq_msg!(self, ProfileQueriesMsg::CacheHit);
472-
self.sess.profiler(|p| p.record_query_hit(Q::NAME));
473-
474472
result
475473
} else {
476474
// We could not load a result from the on-disk cache, so
477475
// recompute.
478-
479-
self.sess.profiler(|p| p.start_query(Q::NAME));
476+
let _prof_timer = self.prof.query_provider(Q::NAME);
480477

481478
// The dep-graph for this computation is already in-place.
482479
let result = self.dep_graph.with_ignore(|| {
483480
Q::compute(self, key)
484481
});
485482

486-
self.sess.profiler(|p| p.end_query(Q::NAME));
487483
result
488484
};
489485

@@ -551,7 +547,7 @@ impl<'tcx> TyCtxt<'tcx> {
551547
key, dep_node);
552548

553549
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
554-
self.sess.profiler(|p| p.start_query(Q::NAME));
550+
let prof_timer = self.prof.query_provider(Q::NAME);
555551

556552
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
557553
self.start_query(job.job.clone(), diagnostics, |tcx| {
@@ -571,7 +567,7 @@ impl<'tcx> TyCtxt<'tcx> {
571567
})
572568
});
573569

574-
self.sess.profiler(|p| p.end_query(Q::NAME));
570+
drop(prof_timer);
575571
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
576572

577573
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
@@ -619,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
619615
let _ = self.get_query::<Q>(DUMMY_SP, key);
620616
} else {
621617
profq_msg!(self, ProfileQueriesMsg::CacheHit);
622-
self.sess.profiler(|p| p.record_query_hit(Q::NAME));
618+
self.prof.query_cache_hit(Q::NAME);
623619
}
624620
}
625621

src/librustc_codegen_llvm/back/lto.rs

+62-43
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
6262
};
6363
let exported_symbols = cgcx.exported_symbols
6464
.as_ref().expect("needs exported symbols for LTO");
65-
let mut symbol_white_list = exported_symbols[&LOCAL_CRATE]
66-
.iter()
67-
.filter_map(symbol_filter)
68-
.collect::<Vec<CString>>();
69-
let _timer = cgcx.profile_activity("generate_symbol_white_list_for_thinlto");
65+
let mut symbol_white_list = {
66+
let _timer = cgcx.prof.generic_activity("LLVM_lto_generate_symbol_white_list");
67+
exported_symbols[&LOCAL_CRATE]
68+
.iter()
69+
.filter_map(symbol_filter)
70+
.collect::<Vec<CString>>()
71+
};
7072
info!("{} symbols to preserve in this crate", symbol_white_list.len());
7173

7274
// If we're performing LTO for the entire crate graph, then for each of our
@@ -95,14 +97,17 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
9597
}
9698

9799
for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
98-
let _timer = cgcx.profile_activity(format!("load: {}", path.display()));
99100
let exported_symbols = cgcx.exported_symbols
100101
.as_ref().expect("needs exported symbols for LTO");
101-
symbol_white_list.extend(
102-
exported_symbols[&cnum]
103-
.iter()
104-
.filter_map(symbol_filter));
102+
{
103+
let _timer = cgcx.prof.generic_activity("LLVM_lto_generate_symbol_white_list");
104+
symbol_white_list.extend(
105+
exported_symbols[&cnum]
106+
.iter()
107+
.filter_map(symbol_filter));
108+
}
105109

110+
let _timer = cgcx.prof.generic_activity("LLVM_lto_load_upstream_bitcode");
106111
let archive = ArchiveRO::open(&path).expect("wanted an rlib");
107112
let bytecodes = archive.iter().filter_map(|child| {
108113
child.ok().and_then(|c| c.name().map(|name| (name, c)))
@@ -189,6 +194,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
189194
symbol_white_list: &[*const libc::c_char])
190195
-> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError>
191196
{
197+
let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_build_monolithic_module");
192198
info!("going for a fat lto");
193199

194200
// Sort out all our lists of incoming modules into two lists.
@@ -287,6 +293,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
287293
// save and persist everything with the original module.
288294
let mut linker = Linker::new(llmod);
289295
for (bc_decoded, name) in serialized_modules {
296+
let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_link_module");
290297
info!("linking {:?}", name);
291298
time_ext(cgcx.time_passes, None, &format!("ll link {:?}", name), || {
292299
let data = bc_decoded.data();
@@ -388,6 +395,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
388395
symbol_white_list: &[*const libc::c_char])
389396
-> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError>
390397
{
398+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
391399
unsafe {
392400
info!("going for that thin, thin LTO");
393401

@@ -601,16 +609,6 @@ impl ModuleBuffer {
601609
llvm::LLVMRustModuleBufferCreate(m)
602610
})
603611
}
604-
605-
pub fn parse<'a>(
606-
&self,
607-
name: &str,
608-
cx: &'a llvm::Context,
609-
handler: &Handler,
610-
) -> Result<&'a llvm::Module, FatalError> {
611-
let name = CString::new(name).unwrap();
612-
parse_module(cx, &name, self.data(), handler)
613-
}
614612
}
615613

616614
impl ModuleBufferMethods for ModuleBuffer {
@@ -723,7 +721,7 @@ pub unsafe fn optimize_thin_module(
723721
// Like with "fat" LTO, get some better optimizations if landing pads
724722
// are disabled by removing all landing pads.
725723
if cgcx.no_landing_pads {
726-
let _timer = cgcx.profile_activity("LLVM_remove_landing_pads");
724+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_remove_landing_pads");
727725
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
728726
save_temp_bitcode(&cgcx, &module, "thin-lto-after-nounwind");
729727
}
@@ -736,26 +734,41 @@ pub unsafe fn optimize_thin_module(
736734
//
737735
// You can find some more comments about these functions in the LLVM
738736
// bindings we've got (currently `PassWrapper.cpp`)
739-
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod) {
740-
let msg = "failed to prepare thin LTO module";
741-
return Err(write::llvm_err(&diag_handler, msg))
737+
{
738+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_rename");
739+
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod) {
740+
let msg = "failed to prepare thin LTO module";
741+
return Err(write::llvm_err(&diag_handler, msg))
742+
}
743+
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
742744
}
743-
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
744-
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
745-
let msg = "failed to prepare thin LTO module";
746-
return Err(write::llvm_err(&diag_handler, msg))
745+
746+
{
747+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_resolve_weak");
748+
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
749+
let msg = "failed to prepare thin LTO module";
750+
return Err(write::llvm_err(&diag_handler, msg))
751+
}
752+
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
747753
}
748-
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
749-
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
750-
let msg = "failed to prepare thin LTO module";
751-
return Err(write::llvm_err(&diag_handler, msg))
754+
755+
{
756+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_internalize");
757+
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
758+
let msg = "failed to prepare thin LTO module";
759+
return Err(write::llvm_err(&diag_handler, msg))
760+
}
761+
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
752762
}
753-
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
754-
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod) {
755-
let msg = "failed to prepare thin LTO module";
756-
return Err(write::llvm_err(&diag_handler, msg))
763+
764+
{
765+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_import");
766+
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod) {
767+
let msg = "failed to prepare thin LTO module";
768+
return Err(write::llvm_err(&diag_handler, msg))
769+
}
770+
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
757771
}
758-
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
759772

760773
// Ok now this is a bit unfortunate. This is also something you won't
761774
// find upstream in LLVM's ThinLTO passes! This is a hack for now to
@@ -786,18 +799,24 @@ pub unsafe fn optimize_thin_module(
786799
// not too much) but for now at least gets LLVM to emit valid DWARF (or
787800
// so it appears). Hopefully we can remove this once upstream bugs are
788801
// fixed in LLVM.
789-
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
790-
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
802+
{
803+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_patch_debuginfo");
804+
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
805+
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
806+
}
791807

792808
// Alright now that we've done everything related to the ThinLTO
793809
// analysis it's time to run some optimizations! Here we use the same
794810
// `run_pass_manager` as the "fat" LTO above except that we tell it to
795811
// populate a thin-specific pass manager, which presumably LLVM treats a
796812
// little differently.
797-
info!("running thin lto passes over {}", module.name);
798-
let config = cgcx.config(module.kind);
799-
run_pass_manager(cgcx, &module, config, true);
800-
save_temp_bitcode(cgcx, &module, "thin-lto-after-pm");
813+
{
814+
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_optimize");
815+
info!("running thin lto passes over {}", module.name);
816+
let config = cgcx.config(module.kind);
817+
run_pass_manager(cgcx, &module, config, true);
818+
save_temp_bitcode(cgcx, &module, "thin-lto-after-pm");
819+
}
801820
}
802821
Ok(module)
803822
}

src/librustc_codegen_llvm/back/write.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
306306
config: &ModuleConfig)
307307
-> Result<(), FatalError>
308308
{
309+
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize");
310+
309311
let llmod = module.module_llvm.llmod();
310312
let llcx = &*module.module_llvm.llcx;
311313
let tm = &*module.module_llvm.tm;
@@ -423,7 +425,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
423425

424426
// Finally, run the actual optimization passes
425427
{
426-
let _timer = cgcx.profile_activity("LLVM_function_passes");
428+
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_function_passes");
427429
time_ext(config.time_passes,
428430
None,
429431
&format!("llvm function passes [{}]", module_name.unwrap()),
@@ -432,7 +434,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
432434
});
433435
}
434436
{
435-
let _timer = cgcx.profile_activity("LLVM_module_passes");
437+
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_module_passes");
436438
time_ext(config.time_passes,
437439
None,
438440
&format!("llvm module passes [{}]", module_name.unwrap()),
@@ -454,7 +456,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
454456
config: &ModuleConfig)
455457
-> Result<CompiledModule, FatalError>
456458
{
457-
let _timer = cgcx.profile_activity("codegen");
459+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen");
458460
{
459461
let llmod = module.module_llvm.llmod();
460462
let llcx = &*module.module_llvm.llcx;
@@ -505,25 +507,26 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
505507

506508

507509
if write_bc || config.emit_bc_compressed || config.embed_bitcode {
508-
let _timer = cgcx.profile_activity("LLVM_make_bitcode");
510+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_make_bitcode");
509511
let thin = ThinBuffer::new(llmod);
510512
let data = thin.data();
511513

512514
if write_bc {
513-
let _timer = cgcx.profile_activity("LLVM_emit_bitcode");
515+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_bitcode");
514516
if let Err(e) = fs::write(&bc_out, data) {
515517
let msg = format!("failed to write bytecode to {}: {}", bc_out.display(), e);
516518
diag_handler.err(&msg);
517519
}
518520
}
519521

520522
if config.embed_bitcode {
521-
let _timer = cgcx.profile_activity("LLVM_embed_bitcode");
523+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_embed_bitcode");
522524
embed_bitcode(cgcx, llcx, llmod, Some(data));
523525
}
524526

525527
if config.emit_bc_compressed {
526-
let _timer = cgcx.profile_activity("LLVM_compress_bitcode");
528+
let _timer =
529+
cgcx.prof.generic_activity("LLVM_module_codegen_emit_compressed_bitcode");
527530
let dst = bc_out.with_extension(RLIB_BYTECODE_EXTENSION);
528531
let data = bytecode::encode(&module.name, data);
529532
if let Err(e) = fs::write(&dst, data) {
@@ -538,7 +541,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
538541
time_ext(config.time_passes, None, &format!("codegen passes [{}]", module_name.unwrap()),
539542
|| -> Result<(), FatalError> {
540543
if config.emit_ir {
541-
let _timer = cgcx.profile_activity("LLVM_emit_ir");
544+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_ir");
542545
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
543546
let out_c = path_to_c_string(&out);
544547

@@ -585,7 +588,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
585588
}
586589

587590
if config.emit_asm || asm_to_obj {
588-
let _timer = cgcx.profile_activity("LLVM_emit_asm");
591+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_asm");
589592
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
590593

591594
// We can't use the same module for asm and binary output, because that triggers
@@ -603,13 +606,13 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
603606
}
604607

605608
if write_obj {
606-
let _timer = cgcx.profile_activity("LLVM_emit_obj");
609+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_obj");
607610
with_codegen(tm, llmod, config.no_builtins, |cpm| {
608611
write_output_file(diag_handler, tm, cpm, llmod, &obj_out,
609612
llvm::FileType::ObjectFile)
610613
})?;
611614
} else if asm_to_obj {
612-
let _timer = cgcx.profile_activity("LLVM_asm_to_obj");
615+
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_asm_to_obj");
613616
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
614617
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
615618

0 commit comments

Comments
 (0)