diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 74a7cc5a8b7..f1408400dee 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -124,7 +124,15 @@ pub(super) fn try_get( let job = match lock.active.entry((*key).clone()) { Entry::Occupied(entry) => { match *entry.get() { - QueryResult::Started(ref job) => job.clone(), + QueryResult::Started(ref job) => { + //For parallel queries, we'll block and wait until the query running + //in another thread has completed. Record how long we wait in the + //self-profiler + #[cfg(parallel_compiler)] + tcx.sess.profiler(|p| p.query_blocked_start(Q::NAME, Q::CATEGORY)); + + job.clone() + }, QueryResult::Poisoned => FatalError.raise(), } } @@ -160,7 +168,10 @@ pub(super) fn try_get( // thread #[cfg(parallel_compiler)] { - if let Err(cycle) = job.r#await(tcx, span) { + let result = job.r#await(tcx, span); + tcx.sess.profiler(|p| p.query_blocked_end(Q::NAME, Q::CATEGORY)); + + if let Err(cycle) = result { return TryGetJob::JobCompleted(Err(cycle)); } } diff --git a/src/librustc/util/profiling.rs b/src/librustc/util/profiling.rs index 0306ce1e6f2..a43b618ca90 100644 --- a/src/librustc/util/profiling.rs +++ b/src/librustc/util/profiling.rs @@ -27,6 +27,8 @@ pub enum ProfilerEvent { QueryCount { query_name: &'static str, category: ProfileCategory, count: usize }, IncrementalLoadResultStart { query_name: &'static str, time: Instant }, IncrementalLoadResultEnd { query_name: &'static str, time: Instant }, + QueryBlockedStart { query_name: &'static str, category: ProfileCategory, time: Instant }, + QueryBlockedEnd { query_name: &'static str, category: ProfileCategory, time: Instant }, } impl ProfilerEvent { @@ -36,13 +38,15 @@ fn is_start_event(&self) -> bool { match self { QueryStart { .. } | GenericActivityStart { .. } | - IncrementalLoadResultStart { .. } => true, + IncrementalLoadResultStart { .. } | + QueryBlockedStart { .. } => true, QueryEnd { .. } | GenericActivityEnd { .. } | QueryCacheHit { .. } | QueryCount { .. } | - IncrementalLoadResultEnd { .. } => false, + IncrementalLoadResultEnd { .. } | + QueryBlockedEnd { .. } => false, } } } @@ -249,6 +253,24 @@ pub fn incremental_load_result_end(&mut self, query_name: &'static str) { }) } + #[inline] + pub fn query_blocked_start(&mut self, query_name: &'static str, category: ProfileCategory) { + self.record(ProfilerEvent::QueryBlockedStart { + query_name, + category, + time: Instant::now(), + }) + } + + #[inline] + pub fn query_blocked_end(&mut self, query_name: &'static str, category: ProfileCategory) { + self.record(ProfilerEvent::QueryBlockedEnd { + query_name, + category, + time: Instant::now(), + }) + } + #[inline] fn record(&mut self, event: ProfilerEvent) { let thread_id = std::thread::current().id(); @@ -343,6 +365,8 @@ fn calculate_thread_results(events: &Vec) -> CalculatedResults { }, //we don't summarize incremental load result events in the simple output mode IncrementalLoadResultStart { .. } | IncrementalLoadResultEnd { .. } => { }, + //we don't summarize parallel query blocking in the simple output mode + QueryBlockedStart { .. } | QueryBlockedEnd { .. } => { }, } }