From: Lukas Kalbertodt Date: Wed, 2 May 2018 10:15:37 +0000 (+0200) Subject: Show elapsed time in minutes if >= 60 secs X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~27^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=88d2886fb3f4ec4b24b8cfba01fe873e93f1704f;p=cargo.git Show elapsed time in minutes if >= 60 secs In large projects with long compile times, seeing "400.65 secs" isn't as clear as seeing the number of minutes (and seconds). --- diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index cd8496202..f167b49de 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -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 {}",