Skip to content

Commit efe703a

Browse files
committed
[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.
1 parent 338f939 commit efe703a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

compiler/rustc_codegen_llvm/src/base.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,23 @@ pub fn compile_codegen_unit(
9797
tcx: TyCtxt<'tcx>,
9898
cgu_name: Symbol,
9999
) -> (ModuleCodegen<ModuleLlvm>, u64) {
100-
let prof_timer = tcx.prof.generic_activity_with_arg("codegen_module", cgu_name.to_string());
101100
let start_time = Instant::now();
102101

103102
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
104103
let (module, _) =
105104
tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
106105
let time_to_codegen = start_time.elapsed();
107-
drop(prof_timer);
108106

109107
// We assume that the cost to run LLVM on a CGU is proportional to
110108
// the time we needed for codegenning it.
111109
let cost = time_to_codegen.as_nanos() as u64;
112110

113111
fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm> {
114112
let cgu = tcx.codegen_unit(cgu_name);
113+
let _prof_timer = tcx.prof.generic_activity_with_args(
114+
"codegen_module",
115+
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
116+
);
115117
// Instantiate monomorphizations without filling out definitions yet...
116118
let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
117119
{

compiler/rustc_data_structures/src/profiling.rs

+22
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ impl SelfProfilerRef {
272272
})
273273
}
274274

275+
#[inline(always)]
276+
pub fn generic_activity_with_args(
277+
&self,
278+
event_label: &'static str,
279+
event_args: &[String],
280+
) -> TimingGuard<'_> {
281+
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
282+
let builder = EventIdBuilder::new(&profiler.profiler);
283+
let event_label = profiler.get_or_alloc_cached_string(event_label);
284+
let event_id = if profiler.event_filter_mask.contains(EventFilter::FUNCTION_ARGS) {
285+
let event_args: Vec<_> = event_args
286+
.iter()
287+
.map(|s| profiler.get_or_alloc_cached_string(&s[..]))
288+
.collect();
289+
builder.from_label_and_args(event_label, &event_args)
290+
} else {
291+
builder.from_label(event_label)
292+
};
293+
TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
294+
})
295+
}
296+
275297
/// Start profiling a query provider. Profiling continues until the
276298
/// TimingGuard returned from this call is dropped.
277299
#[inline(always)]

0 commit comments

Comments
 (0)