Show elapsed time in minutes if >= 60 secs
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>
Wed, 2 May 2018 10:15:37 +0000 (12:15 +0200)
committerLukas Kalbertodt <lukas.kalbertodt@gmail.com>
Wed, 2 May 2018 16:34:59 +0000 (18:34 +0200)
In large projects with long compile times, seeing "400.65 secs" isn't as
clear as seeing the number of minutes (and seconds).

src/cargo/core/compiler/job_queue.rs

index cd8496202650a63fb142d844a4045444b0facc0d..f167b49de64b66d700ed23cd6e5968ec10f1d1fd 100644 (file)
@@ -275,12 +275,30 @@ impl<'a> JobQueue<'a> {
         if profile.debuginfo.is_some() {
             opt_type += " + debuginfo";
         }
-        let duration = cx.bcx.config.creation_time().elapsed();
-        let time_elapsed = format!(
-            "{}.{:02} secs",
-            duration.as_secs(),
-            duration.subsec_nanos() / 10_000_000
-        );
+
+        let time_elapsed = {
+            use std::fmt::Write;
+
+            let duration = cx.bcx.config.creation_time().elapsed();
+            let mut s = String::new();
+            let secs = duration.as_secs();
+
+            if secs >= 60 {
+                // We can safely unwrap, as writing to a `String` never errors
+                write!(s, "{}m ", secs / 60).unwrap();
+            };
+
+            // We can safely unwrap, as writing to a `String` never errors
+            write!(
+                s,
+                "{}.{:02}s",
+                secs % 60,
+                duration.subsec_nanos() / 10_000_000
+            ).unwrap();
+
+            s
+        };
+
         if self.queue.is_empty() {
             let message = format!(
                 "{} [{}] target(s) in {}",