Skip to content

Commit

Permalink
Auto merge of #5456 - LukasKalbertodt:patch-1, r=matklad
Browse files Browse the repository at this point in the history
Show elapsed time in minutes if >= 60 secs

In large projects with long compile times, seeing "428.65 secs" isn't as clear to humans as seeing the number of minutes (and seconds).

**Old**:
```
Finished dev [unoptimized + debuginfo] target(s) in 2.23 secs
Finished dev [unoptimized + debuginfo] target(s) in 63.94 secs
Finished dev [unoptimized + debuginfo] target(s) in 428.65 secs
```

**New**:
```
Finished dev [unoptimized + debuginfo] target(s) in 2.23s
Finished dev [unoptimized + debuginfo] target(s) in 1m 3.94s
Finished dev [unoptimized + debuginfo] target(s) in 7m 8.65s
```

Note that I also changed `secs` to `s`, because `7 mins 8.65 secs` and `7m 8.65 secs` both look strange IMO. But if you disagree and you'd prefer `secs`, just tell me and I'll change it.

I *didn't* add a check for `secs >= 3600` to print the time in hours. I *hope* this is not necessary...
  • Loading branch information
bors committed May 2, 2018
2 parents 31b38fe + 3572813 commit 420f9ec
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
30 changes: 24 additions & 6 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}",
Expand Down
14 changes: 7 additions & 7 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
)),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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",
),
)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
Expand Down Expand Up @@ -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
",
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"));
}

Expand Down Expand Up @@ -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
"));
}

Expand Down
36 changes: 18 additions & 18 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
)),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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
",
),
);
Expand Down Expand Up @@ -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()
)),
Expand All @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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()
)),
Expand Down Expand Up @@ -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
",
),
);
Expand Down Expand Up @@ -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
",
),
);
Expand Down

0 comments on commit 420f9ec

Please sign in to comment.