@@ -44,7 +44,9 @@ use std::fmt;
44
44
use std:: io:: Write ;
45
45
use std:: path:: PathBuf ;
46
46
use std:: time:: Duration ;
47
- use std:: sync:: mpsc;
47
+ use std:: sync:: { Arc , mpsc} ;
48
+
49
+ use parking_lot:: Mutex as PlMutex ;
48
50
49
51
mod code_stats;
50
52
pub mod config;
@@ -127,11 +129,8 @@ pub struct Session {
127
129
/// Used by `-Z profile-queries` in `util::common`.
128
130
pub profile_channel : Lock < Option < mpsc:: Sender < ProfileQueriesMsg > > > ,
129
131
130
- /// Used by `-Z self-profile`.
131
- pub self_profiling_active : bool ,
132
-
133
- /// Used by `-Z self-profile`.
134
- pub self_profiling : Lock < SelfProfiler > ,
132
+ /// Used by -Z self-profile
133
+ pub self_profiling : Option < Arc < PlMutex < SelfProfiler > > > ,
135
134
136
135
/// Some measurements that are being gathered during compilation.
137
136
pub perf_stats : PerfStats ,
@@ -834,27 +833,23 @@ impl Session {
834
833
#[ inline( never) ]
835
834
#[ cold]
836
835
fn profiler_active < F : FnOnce ( & mut SelfProfiler ) -> ( ) > ( & self , f : F ) {
837
- let mut profiler = self . self_profiling . borrow_mut ( ) ;
838
- f ( & mut profiler) ;
836
+ match & self . self_profiling {
837
+ None => bug ! ( "profiler_active() called but there was no profiler active" ) ,
838
+ Some ( profiler) => {
839
+ let mut p = profiler. lock ( ) ;
840
+
841
+ f ( & mut p) ;
842
+ }
843
+ }
839
844
}
840
845
841
846
#[ inline( always) ]
842
847
pub fn profiler < F : FnOnce ( & mut SelfProfiler ) -> ( ) > ( & self , f : F ) {
843
- if unlikely ! ( self . self_profiling_active ) {
848
+ if unlikely ! ( self . self_profiling . is_some ( ) ) {
844
849
self . profiler_active ( f)
845
850
}
846
851
}
847
852
848
- pub fn print_profiler_results ( & self ) {
849
- let mut profiler = self . self_profiling . borrow_mut ( ) ;
850
- profiler. print_results ( & self . opts ) ;
851
- }
852
-
853
- pub fn save_json_results ( & self ) {
854
- let profiler = self . self_profiling . borrow ( ) ;
855
- profiler. save_results ( & self . opts ) ;
856
- }
857
-
858
853
pub fn print_perf_stats ( & self ) {
859
854
println ! (
860
855
"Total time spent computing symbol hashes: {}" ,
@@ -1136,6 +1131,10 @@ pub fn build_session_(
1136
1131
source_map : Lrc < source_map:: SourceMap > ,
1137
1132
driver_lint_caps : FxHashMap < lint:: LintId , lint:: Level > ,
1138
1133
) -> Session {
1134
+ let self_profiler =
1135
+ if sopts. debugging_opts . self_profile { Some ( Arc :: new ( PlMutex :: new ( SelfProfiler :: new ( ) ) ) ) }
1136
+ else { None } ;
1137
+
1139
1138
let host_triple = TargetTriple :: from_triple ( config:: host_triple ( ) ) ;
1140
1139
let host = Target :: search ( & host_triple) . unwrap_or_else ( |e|
1141
1140
span_diagnostic
@@ -1185,9 +1184,6 @@ pub fn build_session_(
1185
1184
CguReuseTracker :: new_disabled ( )
1186
1185
} ;
1187
1186
1188
- let self_profiling_active = sopts. debugging_opts . self_profile ||
1189
- sopts. debugging_opts . profile_json ;
1190
-
1191
1187
let sess = Session {
1192
1188
target : target_cfg,
1193
1189
host,
@@ -1216,8 +1212,7 @@ pub fn build_session_(
1216
1212
imported_macro_spans : OneThread :: new ( RefCell :: new ( FxHashMap :: default ( ) ) ) ,
1217
1213
incr_comp_session : OneThread :: new ( RefCell :: new ( IncrCompSession :: NotInitialized ) ) ,
1218
1214
cgu_reuse_tracker,
1219
- self_profiling_active,
1220
- self_profiling : Lock :: new ( SelfProfiler :: new ( ) ) ,
1215
+ self_profiling : self_profiler,
1221
1216
profile_channel : Lock :: new ( None ) ,
1222
1217
perf_stats : PerfStats {
1223
1218
symbol_hash_time : Lock :: new ( Duration :: from_secs ( 0 ) ) ,
0 commit comments