-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix self profiler ICE on Windows #56170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ use session::config::Options; | |
|
||
use std::fs; | ||
use std::io::{self, StdoutLock, Write}; | ||
use std::time::Instant; | ||
use std::time::{Duration, Instant}; | ||
|
||
macro_rules! define_categories { | ||
($($name:ident,)*) => { | ||
|
@@ -197,7 +197,20 @@ impl SelfProfiler { | |
} | ||
|
||
fn stop_timer(&mut self) -> u64 { | ||
let elapsed = self.current_timer.elapsed(); | ||
let elapsed = if cfg!(windows) { | ||
// On Windows, timers don't always appear to be monotonic (see #51648) | ||
// which can lead to panics when calculating elapsed time. | ||
// Work around this by testing to see if the current time is less than | ||
// our recorded time, and if it is, just returning 0. | ||
let now = Instant::now(); | ||
if self.current_timer >= now { | ||
Duration::new(0, 0) | ||
} else { | ||
self.current_timer.elapsed() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this line (209) be changed to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That seems like a reasonable change to me |
||
} | ||
} else { | ||
self.current_timer.elapsed() | ||
}; | ||
|
||
self.current_timer = Instant::now(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change needed? (Not that it's wrong, just surprised it wasn't already the case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed per se. It wasn't already the case because we showed a very small amount of overhead from turning on the profiler. I think it's probably best to make it opt-in though.