Skip to content

Commit

Permalink
self-profiling: Switch query-blocking measurements to RAII-style API.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Oct 25, 2019
1 parent ee1173a commit 9c08306
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
14 changes: 12 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
}
return TryGetJob::JobCompleted(result);
}

#[cfg(parallel_compiler)]
let query_blocked_prof_timer;

let job = match lock.active.entry((*key).clone()) {
Entry::Occupied(entry) => {
match *entry.get() {
Expand All @@ -98,7 +102,9 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
// in another thread has completed. Record how long we wait in the
// self-profiler.
#[cfg(parallel_compiler)]
tcx.prof.query_blocked_start(Q::NAME);
{
query_blocked_prof_timer = tcx.prof.query_blocked(Q::NAME);
}

job.clone()
},
Expand Down Expand Up @@ -140,7 +146,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
#[cfg(parallel_compiler)]
{
let result = job.r#await(tcx, span);
tcx.prof.query_blocked_end(Q::NAME);

// This `drop()` is not strictly necessary as the binding
// would go out of scope anyway. But it's good to have an
// explicit marker of how far the measurement goes.
drop(query_blocked_prof_timer);

if let Err(cycle) = result {
return TryGetJob::Cycle(Q::handle_cycle_error(tcx, cycle));
Expand Down
26 changes: 7 additions & 19 deletions src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,14 @@ impl SelfProfilerRef {
}

/// Start profiling a query being blocked on a concurrent execution.
/// Profiling continues until `query_blocked_end` is called.
/// Profiling continues until the TimingGuard returned from this call is
/// dropped.
#[inline(always)]
pub fn query_blocked_start(&self, query_name: QueryName) {
self.non_guard_query_event(
|profiler| profiler.query_blocked_event_kind,
query_name,
EventFilter::QUERY_BLOCKED,
TimestampKind::Start,
);
}

/// End profiling a query being blocked on a concurrent execution.
#[inline(always)]
pub fn query_blocked_end(&self, query_name: QueryName) {
self.non_guard_query_event(
|profiler| profiler.query_blocked_event_kind,
query_name,
EventFilter::QUERY_BLOCKED,
TimestampKind::End,
);
pub fn query_blocked(&self, query_name: QueryName) -> TimingGuard<'_> {
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
let event_id = SelfProfiler::get_query_name_string_id(query_name);
TimingGuard::start(profiler, profiler.query_blocked_event_kind, event_id)
})
}

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

0 comments on commit 9c08306

Please sign in to comment.