File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -826,8 +826,10 @@ impl Session {
826
826
}
827
827
828
828
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
+ }
831
833
}
832
834
833
835
pub fn print_profiler_results ( & self ) {
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ use session::config::Options;
12
12
13
13
use std:: fs;
14
14
use std:: io:: { self , StdoutLock , Write } ;
15
- use std:: time:: Instant ;
15
+ use std:: time:: { Duration , Instant } ;
16
16
17
17
macro_rules! define_categories {
18
18
( $( $name: ident, ) * ) => {
@@ -208,7 +208,20 @@ impl SelfProfiler {
208
208
}
209
209
210
210
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
+ } ;
212
225
213
226
self . current_timer = Instant :: now ( ) ;
214
227
You can’t perform that action at this time.
0 commit comments