about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/ty/query/plumbing.rs15
-rw-r--r--src/librustc/util/profiling.rs28
2 files changed, 39 insertions, 4 deletions
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 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
             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 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
             // 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 @@ impl ProfilerEvent {
         match self {
             QueryStart { .. } |
             GenericActivityStart { .. } |
-            IncrementalLoadResultStart { .. } => true,
+            IncrementalLoadResultStart { .. } |
+            QueryBlockedStart { .. } => true,
 
             QueryEnd { .. } |
             GenericActivityEnd { .. } |
             QueryCacheHit { .. } |
             QueryCount { .. } |
-            IncrementalLoadResultEnd { .. } => false,
+            IncrementalLoadResultEnd { .. } |
+            QueryBlockedEnd { .. } => false,
         }
     }
 }
@@ -250,6 +254,24 @@ impl SelfProfiler {
     }
 
     #[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();
         let events = self.events.entry(thread_id).or_default();
@@ -343,6 +365,8 @@ impl SelfProfiler {
                 },
                 //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 { .. } => { },
             }
         }