Skip to content

Commit 5dc37c1

Browse files
authored
Rollup merge of #115736 - Zoxc:time-cleanup, r=wesleywiser
Remove `verbose_generic_activity_with_arg` This removes `verbose_generic_activity_with_arg` and changes users to `generic_activity_with_arg`. This keeps the output of `-Z time` readable while these repeated events are still available with the self profiling mechanism.
2 parents 76e59c7 + c64e15e commit 5dc37c1

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn module_codegen(
269269
),
270270
) -> OngoingModuleCodegen {
271271
let (cgu_name, mut cx, mut module, codegened_functions) =
272-
tcx.prof.verbose_generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
272+
tcx.prof.generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
273273
let cgu = tcx.codegen_unit(cgu_name);
274274
let mono_items = cgu.items_in_deterministic_order(tcx);
275275

@@ -322,35 +322,24 @@ fn module_codegen(
322322
});
323323

324324
OngoingModuleCodegen::Async(std::thread::spawn(move || {
325-
cx.profiler.clone().verbose_generic_activity_with_arg("compile functions", &*cgu_name).run(
326-
|| {
327-
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
328-
cx.profiler.clone(),
329-
)));
330-
331-
let mut cached_context = Context::new();
332-
for codegened_func in codegened_functions {
333-
crate::base::compile_fn(
334-
&mut cx,
335-
&mut cached_context,
336-
&mut module,
337-
codegened_func,
338-
);
339-
}
340-
},
341-
);
325+
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
326+
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
327+
cx.profiler.clone(),
328+
)));
329+
330+
let mut cached_context = Context::new();
331+
for codegened_func in codegened_functions {
332+
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
333+
}
334+
});
342335

343-
let global_asm_object_file = cx
344-
.profiler
345-
.verbose_generic_activity_with_arg("compile assembly", &*cgu_name)
346-
.run(|| {
336+
let global_asm_object_file =
337+
cx.profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
347338
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
348339
})?;
349340

350-
let codegen_result = cx
351-
.profiler
352-
.verbose_generic_activity_with_arg("write object file", &*cgu_name)
353-
.run(|| {
341+
let codegen_result =
342+
cx.profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
354343
emit_cgu(
355344
&global_asm_config.output_filenames,
356345
&cx.profiler,

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pub(crate) fn run_pass_manager(
605605
module: &mut ModuleCodegen<ModuleLlvm>,
606606
thin: bool,
607607
) -> Result<(), FatalError> {
608-
let _timer = cgcx.prof.verbose_generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
608+
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
609609
let config = cgcx.config(module.kind);
610610

611611
// Now we have one massive module inside of llmod. Time to run the

compiler/rustc_middle/src/mir/mod.rs

+37
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_target::abi::{FieldIdx, Size, VariantIdx};
2626

2727
use polonius_engine::Atom;
2828
pub use rustc_ast::Mutability;
29+
use rustc_data_structures::fx::FxHashMap;
2930
use rustc_data_structures::fx::FxHashSet;
3031
use rustc_data_structures::graph::dominators::Dominators;
3132
use rustc_index::{Idx, IndexSlice, IndexVec};
@@ -36,6 +37,8 @@ use rustc_span::{Span, DUMMY_SP};
3637
use either::Either;
3738

3839
use std::borrow::Cow;
40+
use std::cell::RefCell;
41+
use std::collections::hash_map::Entry;
3942
use std::fmt::{self, Debug, Display, Formatter, Write};
4043
use std::ops::{Index, IndexMut};
4144
use std::{iter, mem};
@@ -98,6 +101,36 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
98101
}
99102
}
100103

104+
thread_local! {
105+
static PASS_NAMES: RefCell<FxHashMap<&'static str, &'static str>> = {
106+
RefCell::new(FxHashMap::default())
107+
};
108+
}
109+
110+
/// Converts a MIR pass name into a snake case form to match the profiling naming style.
111+
fn to_profiler_name(type_name: &'static str) -> &'static str {
112+
PASS_NAMES.with(|names| match names.borrow_mut().entry(type_name) {
113+
Entry::Occupied(e) => *e.get(),
114+
Entry::Vacant(e) => {
115+
let snake_case: String = type_name
116+
.chars()
117+
.flat_map(|c| {
118+
if c.is_ascii_uppercase() {
119+
vec!['_', c.to_ascii_lowercase()]
120+
} else if c == '-' {
121+
vec!['_']
122+
} else {
123+
vec![c]
124+
}
125+
})
126+
.collect();
127+
let result = &*String::leak(format!("mir_pass{}", snake_case));
128+
e.insert(result);
129+
result
130+
}
131+
})
132+
}
133+
101134
/// A streamlined trait that you can implement to create a pass; the
102135
/// pass will be named after the type, and it will consist of a main
103136
/// loop that goes over each available MIR and applies `run_pass`.
@@ -107,6 +140,10 @@ pub trait MirPass<'tcx> {
107140
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
108141
}
109142

143+
fn profiler_name(&self) -> &'static str {
144+
to_profiler_name(self.name())
145+
}
146+
110147
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
111148
fn is_enabled(&self, _sess: &Session) -> bool {
112149
true

compiler/rustc_mir_transform/src/pass_manager.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ fn run_passes_inner<'tcx>(
9494
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
9595
trace!(?overridden_passes);
9696

97+
let prof_arg = tcx.sess.prof.enabled().then(|| format!("{:?}", body.source.def_id()));
98+
9799
if !body.should_skip() {
98100
for pass in passes {
99101
let name = pass.name();
@@ -121,7 +123,14 @@ fn run_passes_inner<'tcx>(
121123
validate_body(tcx, body, format!("before pass {name}"));
122124
}
123125

124-
tcx.sess.time(name, || pass.run_pass(tcx, body));
126+
if let Some(prof_arg) = &prof_arg {
127+
tcx.sess
128+
.prof
129+
.generic_activity_with_arg(pass.profiler_name(), &**prof_arg)
130+
.run(|| pass.run_pass(tcx, body));
131+
} else {
132+
pass.run_pass(tcx, body);
133+
}
125134

126135
if dump_enabled {
127136
dump_mir_for_pass(tcx, body, &name, true);

compiler/rustc_query_impl/src/plumbing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
348348
Q: super::QueryConfigRestored<'tcx>,
349349
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
350350
{
351-
let _timer =
352-
qcx.profiler().verbose_generic_activity_with_arg("encode_query_results_for", query.name());
351+
let _timer = qcx.profiler().generic_activity_with_arg("encode_query_results_for", query.name());
353352

354353
assert!(query.query_state(qcx).all_inactive());
355354
let cache = query.query_cache(qcx);

0 commit comments

Comments
 (0)