Skip to content

Commit ebc293b

Browse files
committed
Auto merge of #38645 - nikomatsakis:incr-comp-fix-time-depth, r=nrc
propagate TIME_DEPTH to the helper threads for -Z time-passes Currently, the timing measurements for LLVM passes and the like don't come out indented, which messes up `perf.rust-lang.org`. r? @nrc
2 parents 1d9965b + ad747c5 commit ebc293b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/librustc/util/common.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ pub const FN_OUTPUT_NAME: &'static str = "Output";
2727
#[derive(Clone, Copy, Debug)]
2828
pub struct ErrorReported;
2929

30+
thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
31+
32+
/// Read the current depth of `time()` calls. This is used to
33+
/// encourage indentation across threads.
34+
pub fn time_depth() -> usize {
35+
TIME_DEPTH.with(|slot| slot.get())
36+
}
37+
38+
/// Set the current depth of `time()` calls. The idea is to call
39+
/// `set_time_depth()` with the result from `time_depth()` in the
40+
/// parent thread.
41+
pub fn set_time_depth(depth: usize) {
42+
TIME_DEPTH.with(|slot| slot.set(depth));
43+
}
44+
3045
pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
3146
F: FnOnce() -> T,
3247
{
33-
thread_local!(static DEPTH: Cell<usize> = Cell::new(0));
3448
if !do_it { return f(); }
3549

36-
let old = DEPTH.with(|slot| {
50+
let old = TIME_DEPTH.with(|slot| {
3751
let r = slot.get();
3852
slot.set(r + 1);
3953
r
@@ -56,7 +70,7 @@ pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
5670
mem_string,
5771
what);
5872

59-
DEPTH.with(|slot| slot.set(old));
73+
TIME_DEPTH.with(|slot| slot.set(old));
6074

6175
rv
6276
}

src/librustc_trans/back/write.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use llvm;
1919
use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
2020
use llvm::SMDiagnosticRef;
2121
use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
22-
use util::common::time;
22+
use util::common::{time, time_depth, set_time_depth};
2323
use util::common::path2cstr;
2424
use util::fs::link_or_copy;
2525
use errors::{self, Handler, Level, DiagnosticBuilder};
@@ -1033,7 +1033,10 @@ fn run_work_multithreaded(sess: &Session,
10331033

10341034
let incr_comp_session_dir = sess.incr_comp_session_dir_opt().map(|r| r.clone());
10351035

1036+
let depth = time_depth();
10361037
thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
1038+
set_time_depth(depth);
1039+
10371040
let diag_handler = Handler::with_emitter(true, false, box diag_emitter);
10381041

10391042
// Must construct cgcx inside the proc because it has non-Send

0 commit comments

Comments
 (0)