File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -826,8 +826,10 @@ impl Session {
826826 }
827827
828828 pub fn profiler < F : FnOnce ( & mut SelfProfiler ) -> ( ) > ( & self , f : F ) {
829- let mut profiler = self . self_profiling . borrow_mut ( ) ;
830- f ( & mut profiler) ;
829+ if self . opts . debugging_opts . self_profile {
830+ let mut profiler = self . self_profiling . borrow_mut ( ) ;
831+ f ( & mut profiler) ;
832+ }
831833 }
832834
833835 pub fn print_profiler_results ( & self ) {
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ use session::config::Options;
1212
1313use std:: fs;
1414use std:: io:: { self , StdoutLock , Write } ;
15- use std:: time:: Instant ;
15+ use std:: time:: { Duration , Instant } ;
1616
1717macro_rules! define_categories {
1818 ( $( $name: ident, ) * ) => {
@@ -208,7 +208,20 @@ impl SelfProfiler {
208208 }
209209
210210 fn stop_timer ( & mut self ) -> u64 {
211- let elapsed = self . current_timer . elapsed ( ) ;
211+ let elapsed = if cfg ! ( windows) {
212+ // On Windows, timers don't always appear to be monotonic (see #51648)
213+ // which can lead to panics when calculating elapsed time.
214+ // Work around this by testing to see if the current time is less than
215+ // our recorded time, and if it is, just returning 0.
216+ let now = Instant :: now ( ) ;
217+ if self . current_timer >= now {
218+ Duration :: new ( 0 , 0 )
219+ } else {
220+ self . current_timer . elapsed ( )
221+ }
222+ } else {
223+ self . current_timer . elapsed ( )
224+ } ;
212225
213226 self . current_timer = Instant :: now ( ) ;
214227
You can’t perform that action at this time.
0 commit comments