about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2019-10-26 02:45:59 +0900
committerGitHub <noreply@github.com>2019-10-26 02:45:59 +0900
commit574b0780abfecae976a5dfd3e0accb0c821e18e0 (patch)
tree474b68b3ecdf7795d376e7cdfa5c249fd3141b38
parent9192f3625dfa1289e7982f5e9e6523683081ae74 (diff)
parent9c083068e31e8eb4d4f1d3f649354408d866574c (diff)
downloadrust-574b0780abfecae976a5dfd3e0accb0c821e18e0.tar.gz
rust-574b0780abfecae976a5dfd3e0accb0c821e18e0.zip
Rollup merge of #65800 - michaelwoerister:measureme-0.4.0, r=wesleywiser
self-profiling: Update measureme to 0.4.0 and remove non-RAII methods from profiler.

This PR removes all non-RAII based profiling methods from `SelfProfilerRef` :tada:
It also delegates the `TimingGuard` implementation to `measureme`, now that that is available there.

r? @wesleywiser
-rw-r--r--Cargo.lock4
-rw-r--r--src/librustc/Cargo.toml2
-rw-r--r--src/librustc/ty/query/plumbing.rs14
-rw-r--r--src/librustc/util/profiling.rs114
4 files changed, 32 insertions, 102 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fbac2c7879d..1f78c5f3f75 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1966,9 +1966,9 @@ dependencies = [
 
 [[package]]
 name = "measureme"
-version = "0.3.0"
+version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d09de7dafa3aa334bc806447c7e4de69419723312f4b88b80b561dea66601ce8"
+checksum = "cd21b0e6e1af976b269ce062038fe5e1b9ca2f817ab7a3af09ec4210aebf0d30"
 dependencies = [
  "byteorder",
  "memmap",
diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml
index 93274ef0c92..38631224fd3 100644
--- a/src/librustc/Cargo.toml
+++ b/src/librustc/Cargo.toml
@@ -37,4 +37,4 @@ byteorder = { version = "1.3" }
 chalk-engine = { version = "0.9.0", default-features=false }
 rustc_fs_util = { path = "../librustc_fs_util" }
 smallvec = { version = "0.6.8", features = ["union", "may_dangle"] }
-measureme = "0.3"
+measureme = "0.4"
diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs
index 41b4883793b..538154b035a 100644
--- a/src/librustc/ty/query/plumbing.rs
+++ b/src/librustc/ty/query/plumbing.rs
@@ -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() {
@@ -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()
                         },
@@ -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));
diff --git a/src/librustc/util/profiling.rs b/src/librustc/util/profiling.rs
index bd02e7f5a14..5a1b7f3aa4c 100644
--- a/src/librustc/util/profiling.rs
+++ b/src/librustc/util/profiling.rs
@@ -14,9 +14,12 @@ use measureme::{StringId, TimestampKind};
 /// MmapSerializatioSink is faster on macOS and Linux
 /// but FileSerializationSink is faster on Windows
 #[cfg(not(windows))]
-type Profiler = measureme::Profiler<measureme::MmapSerializationSink>;
+type SerializationSink = measureme::MmapSerializationSink;
 #[cfg(windows)]
-type Profiler = measureme::Profiler<measureme::FileSerializationSink>;
+type SerializationSink = measureme::FileSerializationSink;
+
+type Profiler = measureme::Profiler<SerializationSink>;
+
 
 #[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
 pub enum ProfileCategory {
@@ -131,32 +134,6 @@ impl SelfProfilerRef {
         })
     }
 
-    /// Start profiling a generic activity. Profiling continues until
-    /// `generic_activity_end` is called. The RAII-based `generic_activity`
-    /// usually is the better alternative.
-    #[inline(always)]
-    pub fn generic_activity_start(&self, event_id: &str) {
-        self.non_guard_generic_event(
-            |profiler| profiler.generic_activity_event_kind,
-            |profiler| profiler.profiler.alloc_string(event_id),
-            EventFilter::GENERIC_ACTIVITIES,
-            TimestampKind::Start,
-        );
-    }
-
-    /// End profiling a generic activity that was started with
-    /// `generic_activity_start`. The RAII-based `generic_activity` usually is
-    /// the better alternative.
-    #[inline(always)]
-    pub fn generic_activity_end(&self, event_id: &str) {
-        self.non_guard_generic_event(
-            |profiler| profiler.generic_activity_event_kind,
-            |profiler| profiler.profiler.alloc_string(event_id),
-            EventFilter::GENERIC_ACTIVITIES,
-            TimestampKind::End,
-        );
-    }
-
     /// Start profiling a query provider. Profiling continues until the
     /// TimingGuard returned from this call is dropped.
     #[inline(always)]
@@ -179,26 +156,14 @@ impl SelfProfilerRef {
     }
 
     /// Start profiling a query being blocked on a concurrent execution.
-    /// Profiling continues until `query_blocked_end` is called.
-    #[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.
+    /// Profiling continues until the TimingGuard returned from this call is
+    /// dropped.
     #[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
@@ -238,28 +203,6 @@ impl SelfProfilerRef {
             TimingGuard::none()
         }));
     }
-
-    #[inline(always)]
-    fn non_guard_generic_event<F: FnOnce(&SelfProfiler) -> StringId>(
-        &self,
-        event_kind: fn(&SelfProfiler) -> StringId,
-        event_id: F,
-        event_filter: EventFilter,
-        timestamp_kind: TimestampKind
-    ) {
-        drop(self.exec(event_filter, |profiler| {
-            let thread_id = thread_id_to_u64(std::thread::current().id());
-
-            profiler.profiler.record_event(
-                event_kind(profiler),
-                event_id(profiler),
-                thread_id,
-                timestamp_kind,
-            );
-
-            TimingGuard::none()
-        }));
-    }
 }
 
 pub struct SelfProfiler {
@@ -346,14 +289,7 @@ impl SelfProfiler {
 }
 
 #[must_use]
-pub struct TimingGuard<'a>(Option<TimingGuardInternal<'a>>);
-
-struct TimingGuardInternal<'a> {
-    raw_profiler: &'a Profiler,
-    event_id: StringId,
-    event_kind: StringId,
-    thread_id: u64,
-}
+pub struct TimingGuard<'a>(Option<measureme::TimingGuard<'a, SerializationSink>>);
 
 impl<'a> TimingGuard<'a> {
     #[inline]
@@ -364,14 +300,10 @@ impl<'a> TimingGuard<'a> {
     ) -> TimingGuard<'a> {
         let thread_id = thread_id_to_u64(std::thread::current().id());
         let raw_profiler = &profiler.profiler;
-        raw_profiler.record_event(event_kind, event_id, thread_id, TimestampKind::Start);
-
-        TimingGuard(Some(TimingGuardInternal {
-            raw_profiler,
-            event_kind,
-            event_id,
-            thread_id,
-        }))
+        let timing_guard = raw_profiler.start_recording_interval_event(event_kind,
+                                                                       event_id,
+                                                                       thread_id);
+        TimingGuard(Some(timing_guard))
     }
 
     #[inline]
@@ -379,15 +311,3 @@ impl<'a> TimingGuard<'a> {
         TimingGuard(None)
     }
 }
-
-impl<'a> Drop for TimingGuardInternal<'a> {
-    #[inline]
-    fn drop(&mut self) {
-        self.raw_profiler.record_event(
-            self.event_kind,
-            self.event_id,
-            self.thread_id,
-            TimestampKind::End
-        );
-    }
-}