Skip to content

Commit 5bb96ed

Browse files
committed
Implement more detailed self profiling
Timing data and cache hits/misses are now recorded at the query level. This allows us to show detailed per query information such as total time for each query. To see detailed query information in the summary pass the `-Z verbose` flag. For example: ``` rustc -Z self-profile -Z verbose hello_world.rs ```
1 parent ad43389 commit 5bb96ed

File tree

2 files changed

+345
-182
lines changed

2 files changed

+345
-182
lines changed

src/librustc/ty/query/plumbing.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
113113
let mut lock = cache.borrow_mut();
114114
if let Some(value) = lock.results.get(key) {
115115
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
116-
tcx.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));
116+
tcx.sess.profiler(|p| p.record_query_hit(Q::NAME, Q::CATEGORY));
117117
let result = Ok((value.value.clone(), value.index));
118118
#[cfg(debug_assertions)]
119119
{
@@ -375,7 +375,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
375375

376376
if dep_node.kind.is_anon() {
377377
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
378-
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
378+
self.sess.profiler(|p| p.start_query(Q::NAME, Q::CATEGORY));
379379

380380
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
381381
job.start(self, diagnostics, |tcx| {
@@ -385,7 +385,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
385385
})
386386
});
387387

388-
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
388+
self.sess.profiler(|p| p.end_query(Q::NAME, Q::CATEGORY));
389389
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
390390

391391
self.dep_graph.read_index(dep_node_index);
@@ -452,14 +452,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
452452

453453
let result = if let Some(result) = result {
454454
profq_msg!(self, ProfileQueriesMsg::CacheHit);
455-
self.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));
455+
self.sess.profiler(|p| p.record_query_hit(Q::NAME, Q::CATEGORY));
456456

457457
result
458458
} else {
459459
// We could not load a result from the on-disk cache, so
460460
// recompute.
461461

462-
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
462+
self.sess.profiler(|p| p.start_query(Q::NAME, Q::CATEGORY));
463463

464464
// The diagnostics for this query have already been
465465
// promoted to the current session during
@@ -472,7 +472,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
472472
})
473473
});
474474

475-
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
475+
self.sess.profiler(|p| p.end_query(Q::NAME, Q::CATEGORY));
476476
result
477477
};
478478

@@ -541,7 +541,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
541541
key, dep_node);
542542

543543
profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
544-
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
544+
self.sess.profiler(|p| p.start_query(Q::NAME, Q::CATEGORY));
545545

546546
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
547547
job.start(self, diagnostics, |tcx| {
@@ -559,7 +559,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
559559
})
560560
});
561561

562-
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
562+
self.sess.profiler(|p| p.end_query(Q::NAME, Q::CATEGORY));
563563
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);
564564

565565
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
@@ -602,7 +602,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
602602
let _ = self.get_query::<Q>(DUMMY_SP, key);
603603
} else {
604604
profq_msg!(self, ProfileQueriesMsg::CacheHit);
605-
self.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));
605+
self.sess.profiler(|p| p.record_query_hit(Q::NAME, Q::CATEGORY));
606606
}
607607
}
608608

@@ -729,6 +729,7 @@ macro_rules! define_queries_inner {
729729
sess.profiler(|p| {
730730
$(
731731
p.record_computed_queries(
732+
<queries::$name<'_> as QueryConfig<'_>>::NAME,
732733
<queries::$name<'_> as QueryConfig<'_>>::CATEGORY,
733734
self.$name.lock().results.len()
734735
);

0 commit comments

Comments
 (0)