@@ -43,7 +43,9 @@ use std::fmt;
43
43
use std:: io:: Write ;
44
44
use std:: path:: PathBuf ;
45
45
use std:: time:: Duration ;
46
- use std:: sync:: mpsc;
46
+ use std:: sync:: { Arc , mpsc} ;
47
+
48
+ use parking_lot:: Mutex as PlMutex ;
47
49
48
50
mod code_stats;
49
51
pub mod config;
@@ -126,11 +128,8 @@ pub struct Session {
126
128
/// Used by `-Z profile-queries` in `util::common`.
127
129
pub profile_channel : Lock < Option < mpsc:: Sender < ProfileQueriesMsg > > > ,
128
130
129
- /// Used by `-Z self-profile`.
130
- pub self_profiling_active : bool ,
131
-
132
- /// Used by `-Z self-profile`.
133
- pub self_profiling : Lock < SelfProfiler > ,
131
+ /// Used by -Z self-profile
132
+ pub self_profiling : Option < Arc < PlMutex < SelfProfiler > > > ,
134
133
135
134
/// Some measurements that are being gathered during compilation.
136
135
pub perf_stats : PerfStats ,
@@ -833,27 +832,23 @@ impl Session {
833
832
#[ inline( never) ]
834
833
#[ cold]
835
834
fn profiler_active < F : FnOnce ( & mut SelfProfiler ) -> ( ) > ( & self , f : F ) {
836
- let mut profiler = self . self_profiling . borrow_mut ( ) ;
837
- f ( & mut profiler) ;
835
+ match & self . self_profiling {
836
+ None => bug ! ( "profiler_active() called but there was no profiler active" ) ,
837
+ Some ( profiler) => {
838
+ let mut p = profiler. lock ( ) ;
839
+
840
+ f ( & mut p) ;
841
+ }
842
+ }
838
843
}
839
844
840
845
#[ inline( always) ]
841
846
pub fn profiler < F : FnOnce ( & mut SelfProfiler ) -> ( ) > ( & self , f : F ) {
842
- if unlikely ! ( self . self_profiling_active ) {
847
+ if unlikely ! ( self . self_profiling . is_some ( ) ) {
843
848
self . profiler_active ( f)
844
849
}
845
850
}
846
851
847
- pub fn print_profiler_results ( & self ) {
848
- let mut profiler = self . self_profiling . borrow_mut ( ) ;
849
- profiler. print_results ( & self . opts ) ;
850
- }
851
-
852
- pub fn save_json_results ( & self ) {
853
- let profiler = self . self_profiling . borrow ( ) ;
854
- profiler. save_results ( & self . opts ) ;
855
- }
856
-
857
852
pub fn print_perf_stats ( & self ) {
858
853
println ! (
859
854
"Total time spent computing symbol hashes: {}" ,
@@ -1013,13 +1008,15 @@ impl Session {
1013
1008
1014
1009
pub fn build_session (
1015
1010
sopts : config:: Options ,
1011
+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
1016
1012
local_crate_source_file : Option < PathBuf > ,
1017
1013
registry : errors:: registry:: Registry ,
1018
1014
) -> Session {
1019
1015
let file_path_mapping = sopts. file_path_mapping ( ) ;
1020
1016
1021
1017
build_session_with_source_map (
1022
1018
sopts,
1019
+ self_profiler,
1023
1020
local_crate_source_file,
1024
1021
registry,
1025
1022
Lrc :: new ( source_map:: SourceMap :: new ( file_path_mapping) ) ,
@@ -1029,6 +1026,7 @@ pub fn build_session(
1029
1026
1030
1027
pub fn build_session_with_source_map (
1031
1028
sopts : config:: Options ,
1029
+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
1032
1030
local_crate_source_file : Option < PathBuf > ,
1033
1031
registry : errors:: registry:: Registry ,
1034
1032
source_map : Lrc < source_map:: SourceMap > ,
@@ -1103,11 +1101,12 @@ pub fn build_session_with_source_map(
1103
1101
} ,
1104
1102
) ;
1105
1103
1106
- build_session_ ( sopts, local_crate_source_file, diagnostic_handler, source_map)
1104
+ build_session_ ( sopts, self_profiler , local_crate_source_file, diagnostic_handler, source_map)
1107
1105
}
1108
1106
1109
1107
pub fn build_session_ (
1110
1108
sopts : config:: Options ,
1109
+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
1111
1110
local_crate_source_file : Option < PathBuf > ,
1112
1111
span_diagnostic : errors:: Handler ,
1113
1112
source_map : Lrc < source_map:: SourceMap > ,
@@ -1161,9 +1160,6 @@ pub fn build_session_(
1161
1160
CguReuseTracker :: new_disabled ( )
1162
1161
} ;
1163
1162
1164
- let self_profiling_active = sopts. debugging_opts . self_profile ||
1165
- sopts. debugging_opts . profile_json ;
1166
-
1167
1163
let sess = Session {
1168
1164
target : target_cfg,
1169
1165
host,
@@ -1192,8 +1188,7 @@ pub fn build_session_(
1192
1188
imported_macro_spans : OneThread :: new ( RefCell :: new ( FxHashMap :: default ( ) ) ) ,
1193
1189
incr_comp_session : OneThread :: new ( RefCell :: new ( IncrCompSession :: NotInitialized ) ) ,
1194
1190
cgu_reuse_tracker,
1195
- self_profiling_active,
1196
- self_profiling : Lock :: new ( SelfProfiler :: new ( ) ) ,
1191
+ self_profiling : self_profiler,
1197
1192
profile_channel : Lock :: new ( None ) ,
1198
1193
perf_stats : PerfStats {
1199
1194
symbol_hash_time : Lock :: new ( Duration :: from_secs ( 0 ) ) ,
0 commit comments