Skip to content

Commit 9188bab

Browse files
authored
Rollup merge of rust-lang#68531 - wesleywiser:cleanup_self_profiler, r=michaelwoerister
[self-profiler] Two small cleanups r? @michaelwoerister
2 parents 7e82434 + 2acf5a3 commit 9188bab

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/librustc_data_structures/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(integer_atomics)]
2424
#![feature(test)]
2525
#![feature(associated_type_bounds)]
26+
#![feature(thread_id_value)]
2627
#![cfg_attr(unix, feature(libc))]
2728
#![allow(rustc::default_hash_types)]
2829

src/librustc_data_structures/profiling.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ use std::fs;
8888
use std::path::Path;
8989
use std::process;
9090
use std::sync::Arc;
91-
use std::thread::ThreadId;
9291
use std::time::{Duration, Instant};
9392
use std::u32;
9493

@@ -129,17 +128,13 @@ bitflags::bitflags! {
129128
Self::QUERY_PROVIDERS.bits |
130129
Self::QUERY_BLOCKED.bits |
131130
Self::INCR_CACHE_LOADS.bits;
132-
133-
// empty() and none() aren't const-fns unfortunately
134-
const NONE = 0;
135-
const ALL = !Self::NONE.bits;
136131
}
137132
}
138133

139134
// keep this in sync with the `-Z self-profile-events` help message in librustc_session/options.rs
140135
const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
141-
("none", EventFilter::NONE),
142-
("all", EventFilter::ALL),
136+
("none", EventFilter::empty()),
137+
("all", EventFilter::all()),
143138
("default", EventFilter::DEFAULT),
144139
("generic-activity", EventFilter::GENERIC_ACTIVITIES),
145140
("query-provider", EventFilter::QUERY_PROVIDERS),
@@ -149,10 +144,6 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
149144
("query-keys", EventFilter::QUERY_KEYS),
150145
];
151146

152-
fn thread_id_to_u32(tid: ThreadId) -> u32 {
153-
unsafe { std::mem::transmute::<ThreadId, u64>(tid) as u32 }
154-
}
155-
156147
/// Something that uniquely identifies a query invocation.
157148
pub struct QueryInvocationId(pub u32);
158149

@@ -185,7 +176,7 @@ impl SelfProfilerRef {
185176
// If there is no SelfProfiler then the filter mask is set to NONE,
186177
// ensuring that nothing ever tries to actually access it.
187178
let event_filter_mask =
188-
profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::NONE);
179+
profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::empty());
189180

190181
SelfProfilerRef {
191182
profiler,
@@ -318,7 +309,7 @@ impl SelfProfilerRef {
318309
) {
319310
drop(self.exec(event_filter, |profiler| {
320311
let event_id = StringId::new_virtual(query_invocation_id.0);
321-
let thread_id = thread_id_to_u32(std::thread::current().id());
312+
let thread_id = std::thread::current().id().as_u64() as u32;
322313

323314
profiler.profiler.record_instant_event(
324315
event_kind(profiler),
@@ -477,7 +468,7 @@ impl<'a> TimingGuard<'a> {
477468
event_kind: StringId,
478469
event_id: EventId,
479470
) -> TimingGuard<'a> {
480-
let thread_id = thread_id_to_u32(std::thread::current().id());
471+
let thread_id = std::thread::current().id().as_u64() as u32;
481472
let raw_profiler = &profiler.profiler;
482473
let timing_guard =
483474
raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);

0 commit comments

Comments
 (0)