Skip to content

Commit 321ccbe

Browse files
committed
Auto merge of #65208 - michaelwoerister:sp-events-review-2, r=wesleywiser
self-profiling: Add events for everything except trait selection. This is the followup PR to #64840. Trait selection events are still missing (at least those not covered by regular queries). r? @wesleywiser (or @Mark-Simulacrum if @wesleywiser is not available at the moment)
2 parents e59dab5 + ceb1a9c commit 321ccbe

File tree

9 files changed

+39
-4
lines changed

9 files changed

+39
-4
lines changed

src/librustc/dep_graph/graph.rs

+2
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ impl DepGraph {
845845
// This method will only load queries that will end up in the disk cache.
846846
// Other queries will not be executed.
847847
pub fn exec_cache_promotions(&self, tcx: TyCtxt<'_>) {
848+
let _prof_timer = tcx.prof.generic_activity("incr_comp_query_cache_promotion");
849+
848850
let data = self.data.as_ref().unwrap();
849851
for prev_index in data.colors.values.indices() {
850852
match data.colors.get(prev_index) {

src/librustc/hir/lowering.rs

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ pub fn lower_crate(
242242
// incr. comp. yet.
243243
dep_graph.assert_ignored();
244244

245+
let _prof_timer = sess.prof.generic_activity("hir_lowering");
246+
245247
LoweringContext {
246248
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),
247249
sess,

src/librustc/hir/map/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,8 @@ pub fn map_crate<'hir>(sess: &crate::session::Session,
12221222
forest: &'hir Forest,
12231223
definitions: &'hir Definitions)
12241224
-> Map<'hir> {
1225+
let _prof_timer = sess.prof.generic_activity("build_hir_map");
1226+
12251227
// Build the reverse mapping of `node_to_hir_id`.
12261228
let hir_to_node_id = definitions.node_to_hir_id.iter_enumerated()
12271229
.map(|(node_id, &hir_id)| (hir_id, node_id)).collect();

src/librustc_incremental/persist/load.rs

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
101101
// before we fire the background thread.
102102

103103
let time_passes = sess.time_passes();
104+
let prof = sess.prof.clone();
104105

105106
if sess.opts.incremental.is_none() {
106107
// No incremental compilation.
@@ -161,6 +162,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
161162

162163
MaybeAsync::Async(std::thread::spawn(move || {
163164
time_ext(time_passes, "background load prev dep-graph", move || {
165+
let _prof_timer = prof.generic_activity("incr_comp_load_dep_graph");
166+
164167
match load_data(report_incremental_info, &path) {
165168
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
166169
LoadResult::Error { message } => LoadResult::Error { message },
@@ -198,6 +201,8 @@ pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
198201
return OnDiskCache::new_empty(sess.source_map());
199202
}
200203

204+
let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");
205+
201206
match load_data(sess.opts.debugging_opts.incremental_info, &query_cache_path(sess)) {
202207
LoadResult::Ok{ data: (bytes, start_pos) } => OnDiskCache::new(sess, bytes, start_pos),
203208
_ => OnDiskCache::new_empty(sess.source_map())

src/librustc_incremental/persist/save.rs

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ fn encode_work_product_index(work_products: &FxHashMap<WorkProductId, WorkProduc
241241

242242
fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut Encoder) {
243243
time(tcx.sess, "serialize query result cache", || {
244+
let _timer = tcx.prof.generic_activity("incr_comp_serialize_result_cache");
245+
244246
tcx.serialize_query_result_cache(encoder).unwrap();
245247
})
246248
}

src/librustc_interface/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ pub fn register_plugins<'a>(
250250

251251
if sess.opts.incremental.is_some() {
252252
time(sess, "garbage-collect incremental cache directory", || {
253+
let _prof_timer =
254+
sess.prof.generic_activity("incr_comp_garbage_collect_session_directories");
253255
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
254256
warn!(
255257
"Error while trying to garbage collect incremental \

src/librustc_mir/monomorphize/collector.rs

+7
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ pub fn collect_crate_mono_items(
285285
tcx: TyCtxt<'_>,
286286
mode: MonoItemCollectionMode,
287287
) -> (FxHashSet<MonoItem<'_>>, InliningMap<'_>) {
288+
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector");
289+
288290
let roots = time(tcx.sess, "collecting roots", || {
291+
let _prof_timer = tcx.prof
292+
.generic_activity("monomorphization_collector_root_collections");
289293
collect_roots(tcx, mode)
290294
});
291295

@@ -295,6 +299,9 @@ pub fn collect_crate_mono_items(
295299
let mut inlining_map = MTLock::new(InliningMap::new());
296300

297301
{
302+
let _prof_timer = tcx.prof
303+
.generic_activity("monomorphization_collector_graph_walk");
304+
298305
let visited: MTRef<'_, _> = &mut visited;
299306
let inlining_map: MTRef<'_, _> = &mut inlining_map;
300307

src/librustc_mir/monomorphize/partitioning.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ pub fn partition<'tcx, I>(
134134
where
135135
I: Iterator<Item = MonoItem<'tcx>>,
136136
{
137+
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");
138+
137139
// In the first step, we place all regular monomorphizations into their
138140
// respective 'home' codegen unit. Regular monomorphizations are all
139141
// functions and statics defined in the local crate.
140-
let mut initial_partitioning = place_root_mono_items(tcx, mono_items);
142+
let mut initial_partitioning = {
143+
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
144+
place_root_mono_items(tcx, mono_items)
145+
};
141146

142147
initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
143148

@@ -146,17 +151,20 @@ where
146151
// If the partitioning should produce a fixed count of codegen units, merge
147152
// until that count is reached.
148153
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
154+
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
149155
merge_codegen_units(tcx, &mut initial_partitioning, count);
150-
151156
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
152157
}
153158

154159
// In the next step, we use the inlining map to determine which additional
155160
// monomorphizations have to go into each codegen unit. These additional
156161
// monomorphizations can be drop-glue, functions from external crates, and
157162
// local functions the definition of which is marked with `#[inline]`.
158-
let mut post_inlining = place_inlined_mono_items(initial_partitioning,
159-
inlining_map);
163+
let mut post_inlining = {
164+
let _prof_timer =
165+
tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
166+
place_inlined_mono_items(initial_partitioning, inlining_map)
167+
};
160168

161169
post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
162170

@@ -165,6 +173,8 @@ where
165173
// Next we try to make as many symbols "internal" as possible, so LLVM has
166174
// more freedom to optimize.
167175
if !tcx.sess.opts.cg.link_dead_code {
176+
let _prof_timer =
177+
tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
168178
internalize_symbols(tcx, &mut post_inlining, inlining_map);
169179
}
170180

src/librustc_resolve/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,9 @@ impl<'a> Resolver<'a> {
12551255

12561256
/// Entry point to crate resolution.
12571257
pub fn resolve_crate(&mut self, krate: &Crate) {
1258+
let _prof_timer =
1259+
self.session.prof.generic_activity("resolve_crate");
1260+
12581261
ImportResolver { r: self }.finalize_imports();
12591262
self.finalize_macro_resolutions();
12601263

0 commit comments

Comments
 (0)