Skip to content

rustc_codegen_ssa: add time-passes output for each CGU compilation #81538

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

Closed
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
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ fn reuse_workproduct_for_cgu(

fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodegenResult {
let cgu = tcx.codegen_unit(cgu_name);
let _prof_timer = tcx.prof.extra_verbose_generic_activity(
"codegen_module",
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
);
let mono_items = cgu.items_in_deterministic_order(tcx);

let mut module = new_module(tcx, cgu_name.as_str().to_string());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub(crate) fn run_pass_manager(
config: &ModuleConfig,
thin: bool,
) {
let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &module.name[..]);
let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &[&module.name[..]]);

// Now we have one massive module inside of llmod. Time to run the
// LTO-specific optimization passes that LLVM provides.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,14 @@ pub(crate) unsafe fn optimize(
{
let _timer = cgcx.prof.extra_verbose_generic_activity(
"LLVM_module_optimize_function_passes",
&module.name[..],
&[&module.name[..]],
);
llvm::LLVMRustRunFunctionPassManager(fpm, llmod);
}
{
let _timer = cgcx.prof.extra_verbose_generic_activity(
"LLVM_module_optimize_module_passes",
&module.name[..],
&[&module.name[..]],
);
llvm::LLVMRunPassManager(mpm, llmod);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn compile_codegen_unit(

fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm> {
let cgu = tcx.codegen_unit(cgu_name);
let _prof_timer = tcx.prof.generic_activity_with_args(
let _prof_timer = tcx.prof.extra_verbose_generic_activity(
"codegen_module",
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
) {
if config.time_module && llvm_start_time.is_none() {
*llvm_start_time = Some(prof.extra_verbose_generic_activity("LLVM_passes", "crate"));
*llvm_start_time = Some(prof.extra_verbose_generic_activity("LLVM_passes", &["crate"]));
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ impl SelfProfilerRef {
pub fn extra_verbose_generic_activity<'a, A>(
&'a self,
event_label: &'static str,
event_arg: A,
event_args: &[A],
) -> VerboseTimingGuard<'a>
where
A: Borrow<str> + Into<String>,
{
let message = if self.print_extra_verbose_generic_activities {
Some(format!("{}({})", event_label, event_arg.borrow()))
Some(format!("{}({})", event_label, event_args.join(", ")))
} else {
None
};

VerboseTimingGuard::start(message, self.generic_activity_with_arg(event_label, event_arg))
VerboseTimingGuard::start(message, self.generic_activity_with_args(event_label, event_args))
}

/// Start profiling a generic activity. Profiling continues until the
Expand Down Expand Up @@ -273,18 +273,21 @@ impl SelfProfilerRef {
}

#[inline(always)]
pub fn generic_activity_with_args(
pub fn generic_activity_with_args<A>(
&self,
event_label: &'static str,
event_args: &[String],
) -> TimingGuard<'_> {
event_args: &[A],
) -> TimingGuard<'_>
where
A: Borrow<str> + Into<String>,
{
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
let builder = EventIdBuilder::new(&profiler.profiler);
let event_label = profiler.get_or_alloc_cached_string(event_label);
let event_id = if profiler.event_filter_mask.contains(EventFilter::FUNCTION_ARGS) {
let event_args: Vec<_> = event_args
.iter()
.map(|s| profiler.get_or_alloc_cached_string(&s[..]))
.map(|s| profiler.get_or_alloc_cached_string(s.borrow()))
.collect();
builder.from_label_and_args(event_label, &event_args)
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub fn check_ast_crate<T: EarlyLintPass>(
} else {
for pass in &mut passes {
buffered =
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
sess.prof.extra_verbose_generic_activity("run_lint", &[pass.name()]).run(|| {
early_lint_crate(
sess,
lint_store,
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,20 +462,23 @@ fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints
late_lint_pass_crate(tcx, builtin_lints);
} else {
for pass in &mut passes {
tcx.sess.prof.extra_verbose_generic_activity("run_late_lint", pass.name()).run(|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
});
tcx.sess.prof.extra_verbose_generic_activity("run_late_lint", &[pass.name()]).run(
|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
},
);
}

let mut passes: Vec<_> =
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)()).collect();

for pass in &mut passes {
tcx.sess.prof.extra_verbose_generic_activity("run_late_module_lint", pass.name()).run(
|| {
tcx.sess
.prof
.extra_verbose_generic_activity("run_late_module_lint", &[pass.name()])
.run(|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
},
);
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ where
let _timer = tcx
.sess
.prof
.extra_verbose_generic_activity("encode_query_results_for", std::any::type_name::<Q>());
.extra_verbose_generic_activity("encode_query_results_for", &[std::any::type_name::<Q>()]);

let state = Q::query_state(tcx);
assert!(state.all_inactive());
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
let prof = &tcx.sess.prof;

let (mut format_renderer, mut krate) = prof
.extra_verbose_generic_activity("create_renderer", T::descr())
.extra_verbose_generic_activity("create_renderer", &[T::descr()])
.run(|| T::init(krate, options, render_info, edition, cache, tcx))?;

let mut item = match krate.module.take() {
Expand Down Expand Up @@ -106,6 +106,6 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
.run(|| cx.item(item))?;
}
}
prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
prof.extra_verbose_generic_activity("renderer_after_krate", &[T::descr()])
.run(|| format_renderer.after_krate(&krate, diag))
}