about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-12-29 08:16:58 +0000
committerbors <bors@rust-lang.org>2016-12-29 08:16:58 +0000
commitebc293bcd3fb4122c9be889b7338a9c3089f53ce (patch)
tree5a963455f6645a81330ab86f720c60275887f55a
parent1d9965b5baa9ffe52ff605aaa5f25d09a5e4568c (diff)
parentad747c5869ef7e23e1d29fb47b27ff68f77e14bb (diff)
downloadrust-ebc293bcd3fb4122c9be889b7338a9c3089f53ce.tar.gz
rust-ebc293bcd3fb4122c9be889b7338a9c3089f53ce.zip
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
-rw-r--r--src/librustc/util/common.rs20
-rw-r--r--src/librustc_trans/back/write.rs5
2 files changed, 21 insertions, 4 deletions
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index e01856b2a47..4ddccbfd4c5 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -27,13 +27,27 @@ pub const FN_OUTPUT_NAME: &'static str = "Output";
 #[derive(Clone, Copy, Debug)]
 pub struct ErrorReported;
 
+thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
+
+/// Read the current depth of `time()` calls. This is used to
+/// encourage indentation across threads.
+pub fn time_depth() -> usize {
+    TIME_DEPTH.with(|slot| slot.get())
+}
+
+/// Set the current depth of `time()` calls. The idea is to call
+/// `set_time_depth()` with the result from `time_depth()` in the
+/// parent thread.
+pub fn set_time_depth(depth: usize) {
+    TIME_DEPTH.with(|slot| slot.set(depth));
+}
+
 pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
     F: FnOnce() -> T,
 {
-    thread_local!(static DEPTH: Cell<usize> = Cell::new(0));
     if !do_it { return f(); }
 
-    let old = DEPTH.with(|slot| {
+    let old = TIME_DEPTH.with(|slot| {
         let r = slot.get();
         slot.set(r + 1);
         r
@@ -56,7 +70,7 @@ pub fn time<T, F>(do_it: bool, what: &str, f: F) -> T where
              mem_string,
              what);
 
-    DEPTH.with(|slot| slot.set(old));
+    TIME_DEPTH.with(|slot| slot.set(old));
 
     rv
 }
diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs
index de8814f143e..f17919c38b3 100644
--- a/src/librustc_trans/back/write.rs
+++ b/src/librustc_trans/back/write.rs
@@ -19,7 +19,7 @@ use llvm;
 use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef};
 use llvm::SMDiagnosticRef;
 use {CrateTranslation, ModuleLlvm, ModuleSource, ModuleTranslation};
-use util::common::time;
+use util::common::{time, time_depth, set_time_depth};
 use util::common::path2cstr;
 use util::fs::link_or_copy;
 use errors::{self, Handler, Level, DiagnosticBuilder};
@@ -1033,7 +1033,10 @@ fn run_work_multithreaded(sess: &Session,
 
         let incr_comp_session_dir = sess.incr_comp_session_dir_opt().map(|r| r.clone());
 
+        let depth = time_depth();
         thread::Builder::new().name(format!("codegen-{}", i)).spawn(move || {
+            set_time_depth(depth);
+
             let diag_handler = Handler::with_emitter(true, false, box diag_emitter);
 
             // Must construct cgcx inside the proc because it has non-Send