From 88d2886fb3f4ec4b24b8cfba01fe873e93f1704f Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Wed, 2 May 2018 12:15:37 +0200 Subject: [PATCH 1/2] 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). --- src/cargo/core/compiler/job_queue.rs | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index cd849620265..f167b49de64 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 {}", From 357281374ded32891c875b1d61953bfc6b855ec9 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Wed, 2 May 2018 14:52:40 +0200 Subject: [PATCH 2/2] Adjust tests to new time output format --- tests/testsuite/alt_registry.rs | 14 ++++++------- tests/testsuite/directory.rs | 4 ++-- tests/testsuite/features.rs | 4 ++-- tests/testsuite/registry.rs | 36 ++++++++++++++++----------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 089dac9ce8f..79b2472b94d 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -65,7 +65,7 @@ fn depend_on_alt_registry() { [DOWNLOADING] bar v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 (registry `file://[..]`) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::alt_registry() @@ -84,7 +84,7 @@ fn depend_on_alt_registry() { "\ [COMPILING] bar v0.0.1 (registry `file://[..]`) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -128,7 +128,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() { [COMPILING] baz v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 (registry `file://[..]`) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::alt_registry() @@ -173,7 +173,7 @@ fn depend_on_alt_registry_depends_on_same_registry() { [COMPILING] baz v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 (registry `file://[..]`) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::alt_registry() @@ -219,7 +219,7 @@ fn depend_on_alt_registry_depends_on_crates_io() { [COMPILING] baz v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 (registry `file://[..]`) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), alt_reg = registry::alt_registry(), @@ -267,7 +267,7 @@ fn registry_and_path_dep_works() { "\ [COMPILING] bar v0.0.1 ({dir}/bar) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -420,7 +420,7 @@ fn alt_registry_and_crates_io_deps() { .with_stderr_contains("[COMPILING] crates_io_dep v0.0.1") .with_stderr_contains(&format!("[COMPILING] foo v0.0.1 ({})", p.url())) .with_stderr_contains( - "[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs", + "[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s", ), ) } diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index e91efa47080..db4d3057f96 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -170,7 +170,7 @@ fn simple_install() { " Installing bar v0.1.0 Compiling foo v0.1.0 Compiling bar v0.1.0 - Finished release [optimized] target(s) in [..] secs + Finished release [optimized] target(s) in [..]s Installing [..]bar[..] warning: be sure to add `[..]` to your PATH to be able to run the installed binaries ", @@ -288,7 +288,7 @@ fn install_without_feature_dep() { " Installing bar v0.1.0 Compiling foo v0.1.0 Compiling bar v0.1.0 - Finished release [optimized] target(s) in [..] secs + Finished release [optimized] target(s) in [..]s Installing [..]bar[..] warning: be sure to add `[..]` to your PATH to be able to run the installed binaries ", diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 4030985ccea..676288c7acf 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -335,7 +335,7 @@ warning: Package `foo v0.0.1 ([..])` does not have feature `bar`. It has a requi that name, but only optional dependencies can be used as features. [..] Compiling bar v0.0.1 ([..]) Compiling foo v0.0.1 ([..]) - Finished dev [unoptimized + debuginfo] target(s) in [..] secs + Finished dev [unoptimized + debuginfo] target(s) in [..]s ")); } @@ -388,7 +388,7 @@ that name, but only optional dependencies can be used as features. [..] Compiling baz v0.0.1 ([..]) Compiling bar v0.0.1 ([..]) Compiling foo v0.0.1 ([..]) - Finished dev [unoptimized + debuginfo] target(s) in [..] secs + Finished dev [unoptimized + debuginfo] target(s) in [..]s ")); } diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 8597f144f51..6121f3b8f02 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -45,7 +45,7 @@ fn simple() { [DOWNLOADING] bar v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::registry() @@ -61,7 +61,7 @@ fn simple() { "\ [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -99,7 +99,7 @@ fn deps() { [COMPILING] baz v0.0.1 [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::registry() @@ -270,7 +270,7 @@ required by package `foo v0.0.1 ([..])` [DOWNLOADING] notyet v0.0.1 (registry `file://[..]`) [COMPILING] notyet v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url(), reg = registry::registry() @@ -338,7 +338,7 @@ required by package `foo v0.0.1 ([..])` [DOWNLOADING] notyet v0.0.1 (registry `file://[..]`) [COMPILING] notyet v0.0.1 [COMPILING] foo v0.0.1 ({dir}[..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -373,7 +373,7 @@ fn lockfile_locks() { [DOWNLOADING] bar v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -416,7 +416,7 @@ fn lockfile_locks_transitively() { [COMPILING] baz v0.0.1 [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -465,7 +465,7 @@ fn yanks_are_not_used() { [COMPILING] baz v0.0.1 [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -576,7 +576,7 @@ fn update_with_lockfile_if_packages_missing() { "\ [UPDATING] registry `[..]` [DOWNLOADING] bar v0.0.1 (registry `file://[..]`) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", ), ); @@ -630,7 +630,7 @@ fn update_lockfile() { [DOWNLOADING] [..] v0.0.2 (registry `file://[..]`) [COMPILING] bar v0.0.2 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -655,7 +655,7 @@ fn update_lockfile() { [DOWNLOADING] [..] v0.0.3 (registry `file://[..]`) [COMPILING] bar v0.0.3 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -746,7 +746,7 @@ fn dev_dependency_not_used() { [DOWNLOADING] [..] v0.0.1 (registry `file://[..]`) [COMPILING] bar v0.0.1 [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -858,7 +858,7 @@ fn updating_a_dep() { [COMPILING] bar v0.0.1 [COMPILING] a v0.0.1 ({dir}/a) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -887,7 +887,7 @@ fn updating_a_dep() { [COMPILING] bar v0.1.0 [COMPILING] a v0.0.1 ({dir}/a) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -946,7 +946,7 @@ fn git_and_registry_dep() { [COMPILING] a v0.0.1 [COMPILING] b v0.0.1 ([..]) [COMPILING] foo v0.0.1 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -1022,7 +1022,7 @@ fn update_publish_then_update() { [DOWNLOADING] a v0.1.1 (registry `file://[..]`) [COMPILING] a v0.1.1 [COMPILING] foo v0.5.0 ({dir}) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", dir = p.url() )), @@ -1103,7 +1103,7 @@ fn update_transitive_dependency() { [COMPILING] b v0.1.1 [COMPILING] a v0.1.0 [COMPILING] foo v0.5.0 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", ), ); @@ -1361,7 +1361,7 @@ fn only_download_relevant() { [DOWNLOADING] baz v0.1.0 ([..]) [COMPILING] baz v0.1.0 [COMPILING] bar v0.5.0 ([..]) -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s ", ), );