Skip to content

Commit 574b078

Browse files
authored
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` 🎉 It also delegates the `TimingGuard` implementation to `measureme`, now that that is available there. r? @wesleywiser
2 parents 9192f36 + 9c08306 commit 574b078

File tree

4 files changed

+32
-102
lines changed

4 files changed

+32
-102
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1966,9 +1966,9 @@ dependencies = [
19661966

19671967
[[package]]
19681968
name = "measureme"
1969-
version = "0.3.0"
1969+
version = "0.4.0"
19701970
source = "registry+https://github.com/rust-lang/crates.io-index"
1971-
checksum = "d09de7dafa3aa334bc806447c7e4de69419723312f4b88b80b561dea66601ce8"
1971+
checksum = "cd21b0e6e1af976b269ce062038fe5e1b9ca2f817ab7a3af09ec4210aebf0d30"
19721972
dependencies = [
19731973
"byteorder",
19741974
"memmap",

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ byteorder = { version = "1.3" }
3737
chalk-engine = { version = "0.9.0", default-features=false }
3838
rustc_fs_util = { path = "../librustc_fs_util" }
3939
smallvec = { version = "0.6.8", features = ["union", "may_dangle"] }
40-
measureme = "0.3"
40+
measureme = "0.4"

src/librustc/ty/query/plumbing.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
9090
}
9191
return TryGetJob::JobCompleted(result);
9292
}
93+
94+
#[cfg(parallel_compiler)]
95+
let query_blocked_prof_timer;
96+
9397
let job = match lock.active.entry((*key).clone()) {
9498
Entry::Occupied(entry) => {
9599
match *entry.get() {
@@ -98,7 +102,9 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
98102
// in another thread has completed. Record how long we wait in the
99103
// self-profiler.
100104
#[cfg(parallel_compiler)]
101-
tcx.prof.query_blocked_start(Q::NAME);
105+
{
106+
query_blocked_prof_timer = tcx.prof.query_blocked(Q::NAME);
107+
}
102108

103109
job.clone()
104110
},
@@ -140,7 +146,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
140146
#[cfg(parallel_compiler)]
141147
{
142148
let result = job.r#await(tcx, span);
143-
tcx.prof.query_blocked_end(Q::NAME);
149+
150+
// This `drop()` is not strictly necessary as the binding
151+
// would go out of scope anyway. But it's good to have an
152+
// explicit marker of how far the measurement goes.
153+
drop(query_blocked_prof_timer);
144154

145155
if let Err(cycle) = result {
146156
return TryGetJob::Cycle(Q::handle_cycle_error(tcx, cycle));

src/librustc/util/profiling.rs

+17-97
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ use measureme::{StringId, TimestampKind};
1414
/// MmapSerializatioSink is faster on macOS and Linux
1515
/// but FileSerializationSink is faster on Windows
1616
#[cfg(not(windows))]
17-
type Profiler = measureme::Profiler<measureme::MmapSerializationSink>;
17+
type SerializationSink = measureme::MmapSerializationSink;
1818
#[cfg(windows)]
19-
type Profiler = measureme::Profiler<measureme::FileSerializationSink>;
19+
type SerializationSink = measureme::FileSerializationSink;
20+
21+
type Profiler = measureme::Profiler<SerializationSink>;
22+
2023

2124
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, PartialOrd)]
2225
pub enum ProfileCategory {
@@ -131,32 +134,6 @@ impl SelfProfilerRef {
131134
})
132135
}
133136

134-
/// Start profiling a generic activity. Profiling continues until
135-
/// `generic_activity_end` is called. The RAII-based `generic_activity`
136-
/// usually is the better alternative.
137-
#[inline(always)]
138-
pub fn generic_activity_start(&self, event_id: &str) {
139-
self.non_guard_generic_event(
140-
|profiler| profiler.generic_activity_event_kind,
141-
|profiler| profiler.profiler.alloc_string(event_id),
142-
EventFilter::GENERIC_ACTIVITIES,
143-
TimestampKind::Start,
144-
);
145-
}
146-
147-
/// End profiling a generic activity that was started with
148-
/// `generic_activity_start`. The RAII-based `generic_activity` usually is
149-
/// the better alternative.
150-
#[inline(always)]
151-
pub fn generic_activity_end(&self, event_id: &str) {
152-
self.non_guard_generic_event(
153-
|profiler| profiler.generic_activity_event_kind,
154-
|profiler| profiler.profiler.alloc_string(event_id),
155-
EventFilter::GENERIC_ACTIVITIES,
156-
TimestampKind::End,
157-
);
158-
}
159-
160137
/// Start profiling a query provider. Profiling continues until the
161138
/// TimingGuard returned from this call is dropped.
162139
#[inline(always)]
@@ -179,26 +156,14 @@ impl SelfProfilerRef {
179156
}
180157

181158
/// Start profiling a query being blocked on a concurrent execution.
182-
/// Profiling continues until `query_blocked_end` is called.
183-
#[inline(always)]
184-
pub fn query_blocked_start(&self, query_name: QueryName) {
185-
self.non_guard_query_event(
186-
|profiler| profiler.query_blocked_event_kind,
187-
query_name,
188-
EventFilter::QUERY_BLOCKED,
189-
TimestampKind::Start,
190-
);
191-
}
192-
193-
/// End profiling a query being blocked on a concurrent execution.
159+
/// Profiling continues until the TimingGuard returned from this call is
160+
/// dropped.
194161
#[inline(always)]
195-
pub fn query_blocked_end(&self, query_name: QueryName) {
196-
self.non_guard_query_event(
197-
|profiler| profiler.query_blocked_event_kind,
198-
query_name,
199-
EventFilter::QUERY_BLOCKED,
200-
TimestampKind::End,
201-
);
162+
pub fn query_blocked(&self, query_name: QueryName) -> TimingGuard<'_> {
163+
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
164+
let event_id = SelfProfiler::get_query_name_string_id(query_name);
165+
TimingGuard::start(profiler, profiler.query_blocked_event_kind, event_id)
166+
})
202167
}
203168

204169
/// Start profiling how long it takes to load a query result from the
@@ -238,28 +203,6 @@ impl SelfProfilerRef {
238203
TimingGuard::none()
239204
}));
240205
}
241-
242-
#[inline(always)]
243-
fn non_guard_generic_event<F: FnOnce(&SelfProfiler) -> StringId>(
244-
&self,
245-
event_kind: fn(&SelfProfiler) -> StringId,
246-
event_id: F,
247-
event_filter: EventFilter,
248-
timestamp_kind: TimestampKind
249-
) {
250-
drop(self.exec(event_filter, |profiler| {
251-
let thread_id = thread_id_to_u64(std::thread::current().id());
252-
253-
profiler.profiler.record_event(
254-
event_kind(profiler),
255-
event_id(profiler),
256-
thread_id,
257-
timestamp_kind,
258-
);
259-
260-
TimingGuard::none()
261-
}));
262-
}
263206
}
264207

265208
pub struct SelfProfiler {
@@ -346,14 +289,7 @@ impl SelfProfiler {
346289
}
347290

348291
#[must_use]
349-
pub struct TimingGuard<'a>(Option<TimingGuardInternal<'a>>);
350-
351-
struct TimingGuardInternal<'a> {
352-
raw_profiler: &'a Profiler,
353-
event_id: StringId,
354-
event_kind: StringId,
355-
thread_id: u64,
356-
}
292+
pub struct TimingGuard<'a>(Option<measureme::TimingGuard<'a, SerializationSink>>);
357293

358294
impl<'a> TimingGuard<'a> {
359295
#[inline]
@@ -364,30 +300,14 @@ impl<'a> TimingGuard<'a> {
364300
) -> TimingGuard<'a> {
365301
let thread_id = thread_id_to_u64(std::thread::current().id());
366302
let raw_profiler = &profiler.profiler;
367-
raw_profiler.record_event(event_kind, event_id, thread_id, TimestampKind::Start);
368-
369-
TimingGuard(Some(TimingGuardInternal {
370-
raw_profiler,
371-
event_kind,
372-
event_id,
373-
thread_id,
374-
}))
303+
let timing_guard = raw_profiler.start_recording_interval_event(event_kind,
304+
event_id,
305+
thread_id);
306+
TimingGuard(Some(timing_guard))
375307
}
376308

377309
#[inline]
378310
pub fn none() -> TimingGuard<'a> {
379311
TimingGuard(None)
380312
}
381313
}
382-
383-
impl<'a> Drop for TimingGuardInternal<'a> {
384-
#[inline]
385-
fn drop(&mut self) {
386-
self.raw_profiler.record_event(
387-
self.event_kind,
388-
self.event_id,
389-
self.thread_id,
390-
TimestampKind::End
391-
);
392-
}
393-
}

0 commit comments

Comments
 (0)