[self-profiling] Include the estimated size of each cgu in the profile

This is helpful when looking for CGUs where the size estimate isn't a
good indicator of compilation time.

I verified that moving the profiling timer call doesn't affect the
results.
This commit is contained in:
Wesley Wiser 2020-11-03 07:26:00 -05:00
parent 338f939a8d
commit efe703a01a
2 changed files with 26 additions and 2 deletions

View File

@ -97,14 +97,12 @@ pub fn compile_codegen_unit(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
cgu_name: Symbol, cgu_name: Symbol,
) -> (ModuleCodegen<ModuleLlvm>, u64) { ) -> (ModuleCodegen<ModuleLlvm>, u64) {
let prof_timer = tcx.prof.generic_activity_with_arg("codegen_module", cgu_name.to_string());
let start_time = Instant::now(); let start_time = Instant::now();
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx); let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
let (module, _) = let (module, _) =
tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result); tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
let time_to_codegen = start_time.elapsed(); let time_to_codegen = start_time.elapsed();
drop(prof_timer);
// We assume that the cost to run LLVM on a CGU is proportional to // We assume that the cost to run LLVM on a CGU is proportional to
// the time we needed for codegenning it. // the time we needed for codegenning it.
@ -112,6 +110,10 @@ pub fn compile_codegen_unit(
fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm> { fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm> {
let cgu = tcx.codegen_unit(cgu_name); let cgu = tcx.codegen_unit(cgu_name);
let _prof_timer = tcx.prof.generic_activity_with_args(
"codegen_module",
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
);
// Instantiate monomorphizations without filling out definitions yet... // Instantiate monomorphizations without filling out definitions yet...
let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str()); let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
{ {

View File

@ -272,6 +272,28 @@ impl SelfProfilerRef {
}) })
} }
#[inline(always)]
pub fn generic_activity_with_args(
&self,
event_label: &'static str,
event_args: &[String],
) -> TimingGuard<'_> {
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[..]))
.collect();
builder.from_label_and_args(event_label, &event_args)
} else {
builder.from_label(event_label)
};
TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
})
}
/// Start profiling a query provider. Profiling continues until the /// Start profiling a query provider. Profiling continues until the
/// TimingGuard returned from this call is dropped. /// TimingGuard returned from this call is dropped.
#[inline(always)] #[inline(always)]