Skip to content

Commit e3169e2

Browse files
committed
Auto merge of #5314 - matklad:need-more-time, r=alexcrichton
Try to measure all time it takes to compile code As @killercup noticed on IRC, no-op build by Cargo takes as much as 300 ms (on stable, beta and nightly), which seems unreasonable. However, Cargo wrongly reports ` Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs`, and this might be the reason why we haven't noticed this before. So let's try to measure time slightly better: ``` ~/projects/rustraytracer master* λ time cargo +stable build Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs cargo +stable build 0.16s user 0.02s system 94% cpu 0.195 total ~/projects/rustraytracer master* λ time $c build # Cargo with this patch applied Finished dev [unoptimized + debuginfo] target(s) in 0.31 secs $c build 0.30s user 0.02s system 96% cpu 0.330 total ``` r? @alexcrichton
2 parents e837ce0 + 42304b0 commit e3169e2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cargo/ops/cargo_rustc/job_queue.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ impl<'a> JobQueue<'a> {
148148
scope: &Scope<'a>,
149149
jobserver_helper: &HelperThread,
150150
) -> CargoResult<()> {
151-
use std::time::Instant;
152-
153151
let mut tokens = Vec::new();
154152
let mut queue = Vec::new();
155153
trace!("queue: {:#?}", self.queue);
@@ -165,7 +163,6 @@ impl<'a> JobQueue<'a> {
165163
// successful and otherwise wait for pending work to finish if it failed
166164
// and then immediately return.
167165
let mut error = None;
168-
let start_time = Instant::now();
169166
loop {
170167
// Dequeue as much work as we can, learning about everything
171168
// possible that can run. Note that this is also the point where we
@@ -265,7 +262,7 @@ impl<'a> JobQueue<'a> {
265262
if profile.debuginfo.is_some() {
266263
opt_type += " + debuginfo";
267264
}
268-
let duration = start_time.elapsed();
265+
let duration = cx.config.creation_time().elapsed();
269266
let time_elapsed = format!(
270267
"{}.{1:.2} secs",
271268
duration.as_secs(),

src/cargo/util/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::mem;
1111
use std::path::{Path, PathBuf};
1212
use std::str::FromStr;
1313
use std::sync::{Once, ONCE_INIT};
14+
use std::time::Instant;
1415

1516
use curl::easy::Easy;
1617
use jobserver;
@@ -65,6 +66,7 @@ pub struct Config {
6566
easy: LazyCell<RefCell<Easy>>,
6667
/// Cache of the `SourceId` for crates.io
6768
crates_io_source_id: LazyCell<SourceId>,
69+
creation_time: Instant,
6870
}
6971

7072
impl Config {
@@ -101,6 +103,7 @@ impl Config {
101103
cli_flags: CliUnstable::default(),
102104
easy: LazyCell::new(),
103105
crates_io_source_id: LazyCell::new(),
106+
creation_time: Instant::now(),
104107
}
105108
}
106109

@@ -678,6 +681,10 @@ impl Config {
678681
{
679682
Ok(self.crates_io_source_id.try_borrow_with(f)?.clone())
680683
}
684+
685+
pub fn creation_time(&self) -> Instant {
686+
self.creation_time
687+
}
681688
}
682689

683690
#[derive(Eq, PartialEq, Clone, Copy)]

0 commit comments

Comments
 (0)