Skip to content

Commit 9c08306

Browse files
self-profiling: Switch query-blocking measurements to RAII-style API.
1 parent ee1173a commit 9c08306

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/librustc/ty/query/plumbing.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
9090
}
9191
return TryGetJob::JobCompleted(result);
9292
}
93+
94+
#[cfg(parallel_compiler)]
95+
let query_blocked_prof_timer;
96+
9397
let job = match lock.active.entry((*key).clone()) {
9498
Entry::Occupied(entry) => {
9599
match *entry.get() {
@@ -98,7 +102,9 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
98102
// in another thread has completed. Record how long we wait in the
99103
// self-profiler.
100104
#[cfg(parallel_compiler)]
101-
tcx.prof.query_blocked_start(Q::NAME);
105+
{
106+
query_blocked_prof_timer = tcx.prof.query_blocked(Q::NAME);
107+
}
102108

103109
job.clone()
104110
},
@@ -140,7 +146,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
140146
#[cfg(parallel_compiler)]
141147
{
142148
let result = job.r#await(tcx, span);
143-
tcx.prof.query_blocked_end(Q::NAME);
149+
150+
// This `drop()` is not strictly necessary as the binding
151+
// would go out of scope anyway. But it's good to have an
152+
// explicit marker of how far the measurement goes.
153+
drop(query_blocked_prof_timer);
144154

145155
if let Err(cycle) = result {
146156
return TryGetJob::Cycle(Q::handle_cycle_error(tcx, cycle));

src/librustc/util/profiling.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,14 @@ impl SelfProfilerRef {
156156
}
157157

158158
/// Start profiling a query being blocked on a concurrent execution.
159-
/// Profiling continues until `query_blocked_end` is called.
159+
/// Profiling continues until the TimingGuard returned from this call is
160+
/// dropped.
160161
#[inline(always)]
161-
pub fn query_blocked_start(&self, query_name: QueryName) {
162-
self.non_guard_query_event(
163-
|profiler| profiler.query_blocked_event_kind,
164-
query_name,
165-
EventFilter::QUERY_BLOCKED,
166-
TimestampKind::Start,
167-
);
168-
}
169-
170-
/// End profiling a query being blocked on a concurrent execution.
171-
#[inline(always)]
172-
pub fn query_blocked_end(&self, query_name: QueryName) {
173-
self.non_guard_query_event(
174-
|profiler| profiler.query_blocked_event_kind,
175-
query_name,
176-
EventFilter::QUERY_BLOCKED,
177-
TimestampKind::End,
178-
);
162+
pub fn query_blocked(&self, query_name: QueryName) -> TimingGuard<'_> {
163+
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
164+
let event_id = SelfProfiler::get_query_name_string_id(query_name);
165+
TimingGuard::start(profiler, profiler.query_blocked_event_kind, event_id)
166+
})
179167
}
180168

181169
/// Start profiling how long it takes to load a query result from the

0 commit comments

Comments
 (0)