]> git.lizzy.rs Git - rust.git/commitdiff
Basic incremental stats
authorWesley Wiser <wwiser@gmail.com>
Wed, 30 May 2018 03:12:49 +0000 (23:12 -0400)
committerWesley Wiser <wwiser@gmail.com>
Thu, 2 Aug 2018 22:57:24 +0000 (18:57 -0400)
src/librustc/ty/query/plumbing.rs
src/librustc/util/profiling.rs

index 62e69ffee673f15c80c91e781dd16ce49bb18941..3a07f4859d2fe422f91982cf430f80dc08106e7e 100644 (file)
@@ -118,6 +118,11 @@ pub(super) fn try_get(
             let mut lock = cache.borrow_mut();
             if let Some(value) = lock.results.get(key) {
                 profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
+                tcx.sess.profiler(|p| {
+                    p.record_query(Q::CATEGORY);
+                    p.record_query_hit(Q::CATEGORY);
+                });
+
                 let result = Ok((value.value.clone(), value.index));
                 return TryGetJob::JobCompleted(result);
             }
@@ -379,7 +384,10 @@ fn try_get_with<Q: QueryDescription<'gcx>>(
 
         if dep_node.kind.is_anon() {
             profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
-            self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
+            self.sess.profiler(|p| {
+                p.start_activity(Q::CATEGORY);
+                p.record_query(Q::CATEGORY);
+            });
 
             let res = job.start(self, |tcx| {
                 tcx.dep_graph.with_anon_task(dep_node.kind, || {
@@ -404,6 +412,8 @@ fn try_get_with<Q: QueryDescription<'gcx>>(
         if !dep_node.kind.is_input() {
             if let Some(dep_node_index) = self.try_mark_green_and_read(&dep_node) {
                 profq_msg!(self, ProfileQueriesMsg::CacheHit);
+                self.sess.profiler(|p| p.record_query_hit(Q::CATEGORY));
+
                 return self.load_from_disk_and_cache_in_memory::<Q>(key,
                                                                     job,
                                                                     dep_node_index,
@@ -525,7 +535,10 @@ fn force_query_with_job<Q: QueryDescription<'gcx>>(
                 key, dep_node);
 
         profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
-        self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
+        self.sess.profiler(|p| {
+            p.start_activity(Q::CATEGORY);
+            p.record_query(Q::CATEGORY);
+        });
 
         let res = job.start(self, |tcx| {
             if dep_node.kind.is_eval_always() {
index eb20a85ca69f0fd366bbaa9dc0fb2286e623a189..d8eb5308ed1eca08bae2ef7f3efbfea5145479e3 100644 (file)
@@ -76,23 +76,46 @@ fn set(&mut self, category: ProfileCategory, value: T) {
 
 struct CategoryData {
     times: Categories<u64>,
+    query_counts: Categories<(u64, u64)>,
 }
 
 impl CategoryData {
     fn new() -> CategoryData {
         CategoryData {
             times: Categories::new(),
+            query_counts: Categories::new(),
         }
     }
 
     fn print(&self, lock: &mut StdoutLock) {
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "Parsing", self.times.parsing / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "Expansion", self.times.expansion / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "TypeChecking", self.times.type_checking / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "BorrowChecking", self.times.borrow_checking / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "Codegen", self.times.codegen / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "Linking", self.times.linking / 1_000_000).unwrap();
-        writeln!(lock, "{0: <15} \t\t {1: <15}", "Other", self.times.other / 1_000_000).unwrap();
+        macro_rules! p {
+            ($name:tt, $rustic_name:ident) => {
+                writeln!(
+                   lock,
+                   "{0: <15} \t\t {1: <15}",
+                   $name,
+                   self.times.$rustic_name / 1_000_000
+                ).unwrap();
+                
+                let (hits, total) = self.query_counts.$rustic_name;
+                if total > 0 {
+                    writeln!(
+                        lock,
+                        "\t{} hits {} queries",
+                        hits,
+                        total
+                    ).unwrap();
+                }
+            };
+        }
+
+        p!("Parsing", parsing);
+        p!("Expansion", expansion);
+        p!("TypeChecking", type_checking);
+        p!("BorrowChecking", borrow_checking);
+        p!("Codegen", codegen);
+        p!("Linking", linking);
+        p!("Other", other);
     }
 }
 
@@ -147,6 +170,16 @@ pub fn start_activity(&mut self, category: ProfileCategory) {
         self.timer_stack.push(category);
     }
 
+    pub fn record_query(&mut self, category: ProfileCategory) {
+        let (hits, total) = *self.data.query_counts.get(category);
+        self.data.query_counts.set(category, (hits, total + 1));
+    }
+
+    pub fn record_query_hit(&mut self, category: ProfileCategory) {
+        let (hits, total) = *self.data.query_counts.get(category);
+        self.data.query_counts.set(category, (hits + 1, total));
+    }
+
     pub fn end_activity(&mut self, category: ProfileCategory) {
         match self.timer_stack.pop() {
             None => bug!("end_activity() was called but there was no running activity"),