Skip to content

Commit b0b073c

Browse files
Self-Profiling: Refactor SelfProfiler API to be RAII based where possible.
1 parent bf8491e commit b0b073c

File tree

3 files changed

+244
-110
lines changed

3 files changed

+244
-110
lines changed

src/librustc/session/mod.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::source_map;
3232
use syntax::parse::{self, ParseSess};
3333
use syntax::symbol::Symbol;
3434
use syntax_pos::{MultiSpan, Span};
35-
use crate::util::profiling::SelfProfiler;
35+
use crate::util::profiling::{SelfProfiler, SelfProfilerRef};
3636

3737
use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
3838
use rustc_data_structures::flock;
@@ -129,7 +129,7 @@ pub struct Session {
129129
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,
130130

131131
/// Used by `-Z self-profile`.
132-
pub self_profiling: Option<Arc<SelfProfiler>>,
132+
pub prof: SelfProfilerRef,
133133

134134
/// Some measurements that are being gathered during compilation.
135135
pub perf_stats: PerfStats,
@@ -835,24 +835,6 @@ impl Session {
835835
}
836836
}
837837

838-
#[inline(never)]
839-
#[cold]
840-
fn profiler_active<F: FnOnce(&SelfProfiler) -> ()>(&self, f: F) {
841-
match &self.self_profiling {
842-
None => bug!("profiler_active() called but there was no profiler active"),
843-
Some(profiler) => {
844-
f(&profiler);
845-
}
846-
}
847-
}
848-
849-
#[inline(always)]
850-
pub fn profiler<F: FnOnce(&SelfProfiler) -> ()>(&self, f: F) {
851-
if unlikely!(self.self_profiling.is_some()) {
852-
self.profiler_active(f)
853-
}
854-
}
855-
856838
pub fn print_perf_stats(&self) {
857839
println!(
858840
"Total time spent computing symbol hashes: {}",
@@ -1257,7 +1239,7 @@ fn build_session_(
12571239
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
12581240
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
12591241
cgu_reuse_tracker,
1260-
self_profiling: self_profiler,
1242+
prof: SelfProfilerRef::new(self_profiler),
12611243
profile_channel: Lock::new(None),
12621244
perf_stats: PerfStats {
12631245
symbol_hash_time: Lock::new(Duration::from_secs(0)),

src/librustc/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use crate::ty::CanonicalPolyFnSig;
4545
use crate::util::common::ErrorReported;
4646
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
4747
use crate::util::nodemap::{FxHashMap, FxHashSet};
48+
use crate::util::profiling::SelfProfilerRef;
4849

4950
use errors::DiagnosticBuilder;
5051
use arena::SyncDroplessArena;
@@ -995,6 +996,8 @@ pub struct GlobalCtxt<'tcx> {
995996

996997
pub dep_graph: DepGraph,
997998

999+
pub prof: SelfProfilerRef,
1000+
9981001
/// Common objects.
9991002
pub common: Common<'tcx>,
10001003

@@ -1225,6 +1228,7 @@ impl<'tcx> TyCtxt<'tcx> {
12251228
arena: WorkerLocal::new(|_| Arena::default()),
12261229
interners,
12271230
dep_graph,
1231+
prof: s.prof.clone(),
12281232
common,
12291233
types: common_types,
12301234
lifetimes: common_lifetimes,

0 commit comments

Comments
 (0)