Try to measure all time it takes to compile code
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 7 Apr 2018 14:12:14 +0000 (17:12 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 7 Apr 2018 14:12:14 +0000 (17:12 +0300)
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/util/config.rs

index cf4c936257fd3db3fa324dc6bed6ca0426e326a9..aab373ab251aed60ca0089540574c417a9e4baee 100644 (file)
@@ -148,8 +148,6 @@ impl<'a> JobQueue<'a> {
         scope: &Scope<'a>,
         jobserver_helper: &HelperThread,
     ) -> CargoResult<()> {
-        use std::time::Instant;
-
         let mut tokens = Vec::new();
         let mut queue = Vec::new();
         trace!("queue: {:#?}", self.queue);
@@ -165,7 +163,6 @@ impl<'a> JobQueue<'a> {
         // successful and otherwise wait for pending work to finish if it failed
         // and then immediately return.
         let mut error = None;
-        let start_time = Instant::now();
         loop {
             // Dequeue as much work as we can, learning about everything
             // possible that can run. Note that this is also the point where we
@@ -265,7 +262,7 @@ impl<'a> JobQueue<'a> {
         if profile.debuginfo.is_some() {
             opt_type += " + debuginfo";
         }
-        let duration = start_time.elapsed();
+        let duration = cx.config.creation_time().elapsed();
         let time_elapsed = format!(
             "{}.{1:.2} secs",
             duration.as_secs(),
index 19b4312bca29606a2debce8ae5ec087d8bed721f..281165ec209a49424a8098f7971d5259f9d8741e 100644 (file)
@@ -11,6 +11,7 @@ use std::mem;
 use std::path::{Path, PathBuf};
 use std::str::FromStr;
 use std::sync::{Once, ONCE_INIT};
+use std::time::Instant;
 
 use curl::easy::Easy;
 use jobserver;
@@ -65,6 +66,7 @@ pub struct Config {
     easy: LazyCell<RefCell<Easy>>,
     /// Cache of the `SourceId` for crates.io
     crates_io_source_id: LazyCell<SourceId>,
+    creation_time: Instant,
 }
 
 impl Config {
@@ -101,6 +103,7 @@ impl Config {
             cli_flags: CliUnstable::default(),
             easy: LazyCell::new(),
             crates_io_source_id: LazyCell::new(),
+            creation_time: Instant::now(),
         }
     }
 
@@ -678,6 +681,10 @@ impl Config {
     {
         Ok(self.crates_io_source_id.try_borrow_with(f)?.clone())
     }
+
+    pub fn creation_time(&self) -> Instant {
+        self.creation_time
+    }
 }
 
 #[derive(Eq, PartialEq, Clone, Copy)]