Skip to content

Commit

Permalink
Rollup merge of rust-lang#56170 - wesleywiser:fix_self_profiler_windo…
Browse files Browse the repository at this point in the history
…ws, r=estebank

Fix self profiler ICE on Windows

Fixes rust-lang#51648
  • Loading branch information
pietroalbini committed Nov 25, 2018
2 parents 989678e + dce1c45 commit e03fa3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,10 @@ impl Session {
}

pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) {
let mut profiler = self.self_profiling.borrow_mut();
f(&mut profiler);
if self.opts.debugging_opts.self_profile {
let mut profiler = self.self_profiling.borrow_mut();
f(&mut profiler);
}
}

pub fn print_profiler_results(&self) {
Expand Down
17 changes: 15 additions & 2 deletions src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,)*) => {
Expand Down Expand Up @@ -208,7 +208,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()
}
} else {
self.current_timer.elapsed()
};

self.current_timer = Instant::now();

Expand Down

0 comments on commit e03fa3e

Please sign in to comment.