@@ -43,7 +43,9 @@ use std::fmt;
4343use std:: io:: Write ;
4444use std:: path:: PathBuf ;
4545use std:: time:: Duration ;
46- use std:: sync:: mpsc;
46+ use std:: sync:: { Arc , mpsc} ;
47+
48+ use parking_lot:: Mutex as PlMutex ;
4749
4850mod code_stats;
4951pub mod config;
@@ -126,11 +128,8 @@ pub struct Session {
126128 /// Used by `-Z profile-queries` in `util::common`.
127129 pub profile_channel : Lock < Option < mpsc:: Sender < ProfileQueriesMsg > > > ,
128130
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 > > > ,
134133
135134 /// Some measurements that are being gathered during compilation.
136135 pub perf_stats : PerfStats ,
@@ -833,27 +832,23 @@ impl Session {
833832 #[ inline( never) ]
834833 #[ cold]
835834 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+ }
838843 }
839844
840845 #[ inline( always) ]
841846 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 ( ) ) {
843848 self . profiler_active ( f)
844849 }
845850 }
846851
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-
857852 pub fn print_perf_stats ( & self ) {
858853 println ! (
859854 "Total time spent computing symbol hashes: {}" ,
@@ -1013,13 +1008,15 @@ impl Session {
10131008
10141009pub fn build_session (
10151010 sopts : config:: Options ,
1011+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
10161012 local_crate_source_file : Option < PathBuf > ,
10171013 registry : errors:: registry:: Registry ,
10181014) -> Session {
10191015 let file_path_mapping = sopts. file_path_mapping ( ) ;
10201016
10211017 build_session_with_source_map (
10221018 sopts,
1019+ self_profiler,
10231020 local_crate_source_file,
10241021 registry,
10251022 Lrc :: new ( source_map:: SourceMap :: new ( file_path_mapping) ) ,
@@ -1029,6 +1026,7 @@ pub fn build_session(
10291026
10301027pub fn build_session_with_source_map (
10311028 sopts : config:: Options ,
1029+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
10321030 local_crate_source_file : Option < PathBuf > ,
10331031 registry : errors:: registry:: Registry ,
10341032 source_map : Lrc < source_map:: SourceMap > ,
@@ -1103,11 +1101,12 @@ pub fn build_session_with_source_map(
11031101 } ,
11041102 ) ;
11051103
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)
11071105}
11081106
11091107pub fn build_session_ (
11101108 sopts : config:: Options ,
1109+ self_profiler : Option < Arc < PlMutex < SelfProfiler > > > ,
11111110 local_crate_source_file : Option < PathBuf > ,
11121111 span_diagnostic : errors:: Handler ,
11131112 source_map : Lrc < source_map:: SourceMap > ,
@@ -1161,9 +1160,6 @@ pub fn build_session_(
11611160 CguReuseTracker :: new_disabled ( )
11621161 } ;
11631162
1164- let self_profiling_active = sopts. debugging_opts . self_profile ||
1165- sopts. debugging_opts . profile_json ;
1166-
11671163 let sess = Session {
11681164 target : target_cfg,
11691165 host,
@@ -1192,8 +1188,7 @@ pub fn build_session_(
11921188 imported_macro_spans : OneThread :: new ( RefCell :: new ( FxHashMap :: default ( ) ) ) ,
11931189 incr_comp_session : OneThread :: new ( RefCell :: new ( IncrCompSession :: NotInitialized ) ) ,
11941190 cgu_reuse_tracker,
1195- self_profiling_active,
1196- self_profiling : Lock :: new ( SelfProfiler :: new ( ) ) ,
1191+ self_profiling : self_profiler,
11971192 profile_channel : Lock :: new ( None ) ,
11981193 perf_stats : PerfStats {
11991194 symbol_hash_time : Lock :: new ( Duration :: from_secs ( 0 ) ) ,
0 commit comments