Skip to content

Commit

Permalink
Rollup merge of rust-lang#65800 - michaelwoerister:measureme-0.4.0, r…
Browse files Browse the repository at this point in the history
…=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` 🎉
It also delegates the `TimingGuard` implementation to `measureme`, now that that is available there.

r? @wesleywiser
  • Loading branch information
Centril committed Oct 25, 2019
2 parents affcac6 + 9c08306 commit d43c665
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 102 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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
114 changes: 17 additions & 97 deletions src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -364,30 +300,14 @@ 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]
pub fn none() -> 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
);
}
}

0 comments on commit d43c665

Please sign in to comment.