Skip to content

Commit 420f9ec

Browse files
committed
Auto merge of #5456 - LukasKalbertodt:patch-1, r=matklad
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...
2 parents 31b38fe + 3572813 commit 420f9ec

File tree

5 files changed

+53
-35
lines changed

5 files changed

+53
-35
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,30 @@ impl<'a> JobQueue<'a> {
275275
if profile.debuginfo.is_some() {
276276
opt_type += " + debuginfo";
277277
}
278-
let duration = cx.bcx.config.creation_time().elapsed();
279-
let time_elapsed = format!(
280-
"{}.{:02} secs",
281-
duration.as_secs(),
282-
duration.subsec_nanos() / 10_000_000
283-
);
278+
279+
let time_elapsed = {
280+
use std::fmt::Write;
281+
282+
let duration = cx.bcx.config.creation_time().elapsed();
283+
let mut s = String::new();
284+
let secs = duration.as_secs();
285+
286+
if secs >= 60 {
287+
// We can safely unwrap, as writing to a `String` never errors
288+
write!(s, "{}m ", secs / 60).unwrap();
289+
};
290+
291+
// We can safely unwrap, as writing to a `String` never errors
292+
write!(
293+
s,
294+
"{}.{:02}s",
295+
secs % 60,
296+
duration.subsec_nanos() / 10_000_000
297+
).unwrap();
298+
299+
s
300+
};
301+
284302
if self.queue.is_empty() {
285303
let message = format!(
286304
"{} [{}] target(s) in {}",

tests/testsuite/alt_registry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn depend_on_alt_registry() {
6565
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
6666
[COMPILING] bar v0.0.1 (registry `file://[..]`)
6767
[COMPILING] foo v0.0.1 ({dir})
68-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
68+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
6969
",
7070
dir = p.url(),
7171
reg = registry::alt_registry()
@@ -84,7 +84,7 @@ fn depend_on_alt_registry() {
8484
"\
8585
[COMPILING] bar v0.0.1 (registry `file://[..]`)
8686
[COMPILING] foo v0.0.1 ({dir})
87-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
87+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
8888
",
8989
dir = p.url()
9090
)),
@@ -128,7 +128,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
128128
[COMPILING] baz v0.0.1 (registry `file://[..]`)
129129
[COMPILING] bar v0.0.1 (registry `file://[..]`)
130130
[COMPILING] foo v0.0.1 ({dir})
131-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
131+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
132132
",
133133
dir = p.url(),
134134
reg = registry::alt_registry()
@@ -173,7 +173,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
173173
[COMPILING] baz v0.0.1 (registry `file://[..]`)
174174
[COMPILING] bar v0.0.1 (registry `file://[..]`)
175175
[COMPILING] foo v0.0.1 ({dir})
176-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
176+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
177177
",
178178
dir = p.url(),
179179
reg = registry::alt_registry()
@@ -219,7 +219,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
219219
[COMPILING] baz v0.0.1 (registry `file://[..]`)
220220
[COMPILING] bar v0.0.1 (registry `file://[..]`)
221221
[COMPILING] foo v0.0.1 ({dir})
222-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
222+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
223223
",
224224
dir = p.url(),
225225
alt_reg = registry::alt_registry(),
@@ -267,7 +267,7 @@ fn registry_and_path_dep_works() {
267267
"\
268268
[COMPILING] bar v0.0.1 ({dir}/bar)
269269
[COMPILING] foo v0.0.1 ({dir})
270-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
270+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
271271
",
272272
dir = p.url()
273273
)),
@@ -420,7 +420,7 @@ fn alt_registry_and_crates_io_deps() {
420420
.with_stderr_contains("[COMPILING] crates_io_dep v0.0.1")
421421
.with_stderr_contains(&format!("[COMPILING] foo v0.0.1 ({})", p.url()))
422422
.with_stderr_contains(
423-
"[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs",
423+
"[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s",
424424
),
425425
)
426426
}

tests/testsuite/directory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn simple_install() {
170170
" Installing bar v0.1.0
171171
Compiling foo v0.1.0
172172
Compiling bar v0.1.0
173-
Finished release [optimized] target(s) in [..] secs
173+
Finished release [optimized] target(s) in [..]s
174174
Installing [..]bar[..]
175175
warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
176176
",
@@ -288,7 +288,7 @@ fn install_without_feature_dep() {
288288
" Installing bar v0.1.0
289289
Compiling foo v0.1.0
290290
Compiling bar v0.1.0
291-
Finished release [optimized] target(s) in [..] secs
291+
Finished release [optimized] target(s) in [..]s
292292
Installing [..]bar[..]
293293
warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
294294
",

tests/testsuite/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ warning: Package `foo v0.0.1 ([..])` does not have feature `bar`. It has a requi
335335
that name, but only optional dependencies can be used as features. [..]
336336
Compiling bar v0.0.1 ([..])
337337
Compiling foo v0.0.1 ([..])
338-
Finished dev [unoptimized + debuginfo] target(s) in [..] secs
338+
Finished dev [unoptimized + debuginfo] target(s) in [..]s
339339
"));
340340
}
341341

@@ -388,7 +388,7 @@ that name, but only optional dependencies can be used as features. [..]
388388
Compiling baz v0.0.1 ([..])
389389
Compiling bar v0.0.1 ([..])
390390
Compiling foo v0.0.1 ([..])
391-
Finished dev [unoptimized + debuginfo] target(s) in [..] secs
391+
Finished dev [unoptimized + debuginfo] target(s) in [..]s
392392
"));
393393
}
394394

tests/testsuite/registry.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn simple() {
4545
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
4646
[COMPILING] bar v0.0.1
4747
[COMPILING] foo v0.0.1 ({dir})
48-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
48+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
4949
",
5050
dir = p.url(),
5151
reg = registry::registry()
@@ -61,7 +61,7 @@ fn simple() {
6161
"\
6262
[COMPILING] bar v0.0.1
6363
[COMPILING] foo v0.0.1 ({dir})
64-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
64+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
6565
",
6666
dir = p.url()
6767
)),
@@ -99,7 +99,7 @@ fn deps() {
9999
[COMPILING] baz v0.0.1
100100
[COMPILING] bar v0.0.1
101101
[COMPILING] foo v0.0.1 ({dir})
102-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
102+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
103103
",
104104
dir = p.url(),
105105
reg = registry::registry()
@@ -270,7 +270,7 @@ required by package `foo v0.0.1 ([..])`
270270
[DOWNLOADING] notyet v0.0.1 (registry `file://[..]`)
271271
[COMPILING] notyet v0.0.1
272272
[COMPILING] foo v0.0.1 ({dir})
273-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
273+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
274274
",
275275
dir = p.url(),
276276
reg = registry::registry()
@@ -338,7 +338,7 @@ required by package `foo v0.0.1 ([..])`
338338
[DOWNLOADING] notyet v0.0.1 (registry `file://[..]`)
339339
[COMPILING] notyet v0.0.1
340340
[COMPILING] foo v0.0.1 ({dir}[..])
341-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
341+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
342342
",
343343
dir = p.url()
344344
)),
@@ -373,7 +373,7 @@ fn lockfile_locks() {
373373
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
374374
[COMPILING] bar v0.0.1
375375
[COMPILING] foo v0.0.1 ({dir})
376-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
376+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
377377
",
378378
dir = p.url()
379379
)),
@@ -416,7 +416,7 @@ fn lockfile_locks_transitively() {
416416
[COMPILING] baz v0.0.1
417417
[COMPILING] bar v0.0.1
418418
[COMPILING] foo v0.0.1 ({dir})
419-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
419+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
420420
",
421421
dir = p.url()
422422
)),
@@ -465,7 +465,7 @@ fn yanks_are_not_used() {
465465
[COMPILING] baz v0.0.1
466466
[COMPILING] bar v0.0.1
467467
[COMPILING] foo v0.0.1 ({dir})
468-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
468+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
469469
",
470470
dir = p.url()
471471
)),
@@ -576,7 +576,7 @@ fn update_with_lockfile_if_packages_missing() {
576576
"\
577577
[UPDATING] registry `[..]`
578578
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
579-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
579+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
580580
",
581581
),
582582
);
@@ -630,7 +630,7 @@ fn update_lockfile() {
630630
[DOWNLOADING] [..] v0.0.2 (registry `file://[..]`)
631631
[COMPILING] bar v0.0.2
632632
[COMPILING] foo v0.0.1 ({dir})
633-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
633+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
634634
",
635635
dir = p.url()
636636
)),
@@ -655,7 +655,7 @@ fn update_lockfile() {
655655
[DOWNLOADING] [..] v0.0.3 (registry `file://[..]`)
656656
[COMPILING] bar v0.0.3
657657
[COMPILING] foo v0.0.1 ({dir})
658-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
658+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
659659
",
660660
dir = p.url()
661661
)),
@@ -746,7 +746,7 @@ fn dev_dependency_not_used() {
746746
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
747747
[COMPILING] bar v0.0.1
748748
[COMPILING] foo v0.0.1 ({dir})
749-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
749+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
750750
",
751751
dir = p.url()
752752
)),
@@ -858,7 +858,7 @@ fn updating_a_dep() {
858858
[COMPILING] bar v0.0.1
859859
[COMPILING] a v0.0.1 ({dir}/a)
860860
[COMPILING] foo v0.0.1 ({dir})
861-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
861+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
862862
",
863863
dir = p.url()
864864
)),
@@ -887,7 +887,7 @@ fn updating_a_dep() {
887887
[COMPILING] bar v0.1.0
888888
[COMPILING] a v0.0.1 ({dir}/a)
889889
[COMPILING] foo v0.0.1 ({dir})
890-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
890+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
891891
",
892892
dir = p.url()
893893
)),
@@ -946,7 +946,7 @@ fn git_and_registry_dep() {
946946
[COMPILING] a v0.0.1
947947
[COMPILING] b v0.0.1 ([..])
948948
[COMPILING] foo v0.0.1 ({dir})
949-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
949+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
950950
",
951951
dir = p.url()
952952
)),
@@ -1022,7 +1022,7 @@ fn update_publish_then_update() {
10221022
[DOWNLOADING] a v0.1.1 (registry `file://[..]`)
10231023
[COMPILING] a v0.1.1
10241024
[COMPILING] foo v0.5.0 ({dir})
1025-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
1025+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
10261026
",
10271027
dir = p.url()
10281028
)),
@@ -1103,7 +1103,7 @@ fn update_transitive_dependency() {
11031103
[COMPILING] b v0.1.1
11041104
[COMPILING] a v0.1.0
11051105
[COMPILING] foo v0.5.0 ([..])
1106-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
1106+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
11071107
",
11081108
),
11091109
);
@@ -1361,7 +1361,7 @@ fn only_download_relevant() {
13611361
[DOWNLOADING] baz v0.1.0 ([..])
13621362
[COMPILING] baz v0.1.0
13631363
[COMPILING] bar v0.5.0 ([..])
1364-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
1364+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
13651365
",
13661366
),
13671367
);

0 commit comments

Comments
 (0)