Skip to content

Commit dbefa83

Browse files
committed
[WIP] Add timing messages
1 parent 677e542 commit dbefa83

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

build_system/build_backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub(crate) fn build_backend(
4545
eprintln!("[BUILD] rustc_codegen_cranelift");
4646
crate::utils::spawn_and_wait(cmd);
4747

48+
super::time("Built backend");
49+
4850
CG_CLIF
4951
.target_dir(dirs)
5052
.join(&bootstrap_host_compiler.triple)

build_system/build_sysroot.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub(crate) fn build_sysroot(
3030
BIN_DIR.ensure_exists(dirs);
3131
LIB_DIR.ensure_exists(dirs);
3232

33+
super::time(" Ensured clean sysroot");
34+
3335
let is_native = bootstrap_host_compiler.triple == target_triple;
3436

3537
let cg_clif_dylib_path = match cg_clif_dylib_src {
@@ -50,6 +52,8 @@ pub(crate) fn build_sysroot(
5052
CodegenBackend::Builtin(name) => CodegenBackend::Builtin(name.clone()),
5153
};
5254

55+
super::time(" Copied backend");
56+
5357
// Build and copy rustc and cargo wrappers
5458
let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin");
5559
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
@@ -80,8 +84,12 @@ pub(crate) fn build_sysroot(
8084
}
8185
spawn_and_wait(build_cargo_wrapper_cmd);
8286
try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
87+
88+
super::time(&format!(" Built wrapper {wrapper}"));
8389
}
8490

91+
super::time(" Built wrappers");
92+
8593
let host = build_sysroot_for_triple(
8694
dirs,
8795
channel,
@@ -136,6 +144,9 @@ pub(crate) fn build_sysroot(
136144
if !is_native {
137145
target_compiler.set_cross_linker_and_runner();
138146
}
147+
148+
super::time("Built sysroot");
149+
139150
target_compiler
140151
}
141152

build_system/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![warn(rust_2018_idioms)]
22
#![warn(unused_lifetimes)]
33
#![warn(unreachable_pub)]
4-
54
use std::path::PathBuf;
5+
use std::sync::{Mutex, OnceLock};
6+
use std::time::{Duration, Instant};
67
use std::{env, process};
78

89
use self::utils::Compiler;
@@ -19,6 +20,18 @@ mod shared_utils;
1920
mod tests;
2021
mod utils;
2122

23+
static STARTUP_TIME: OnceLock<Instant> = OnceLock::new();
24+
static PREVIOUS_STEP: Mutex<Option<Instant>> = Mutex::new(None);
25+
26+
fn time(step: &str) {
27+
let now = Instant::now();
28+
let mut previous_step = PREVIOUS_STEP.lock().unwrap();
29+
let delta =
30+
previous_step.map(|previous_step| now - previous_step).unwrap_or(Duration::from_secs(0));
31+
*previous_step = Some(now);
32+
println!("{step:<30} @ {:?} (+ {:?})", now - *STARTUP_TIME.get().unwrap(), delta);
33+
}
34+
2235
fn usage() {
2336
eprintln!("{}", include_str!("usage.txt"));
2437
}
@@ -54,6 +67,8 @@ enum CodegenBackend {
5467
}
5568

5669
fn main() {
70+
STARTUP_TIME.set(Instant::now()).unwrap();
71+
5772
if env::var_os("RUST_BACKTRACE").is_none() {
5873
env::set_var("RUST_BACKTRACE", "1");
5974
}
@@ -201,6 +216,8 @@ fn main() {
201216
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
202217
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
203218

219+
time("Inited");
220+
204221
let cg_clif_dylib = if let Some(name) = use_backend {
205222
CodegenBackend::Builtin(name)
206223
} else {

build_system/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ pub(crate) fn run_tests(
278278

279279
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
280280
runner.run_testsuite(NO_SYSROOT_SUITE);
281+
super::time("Ran testsuite no_sysroot");
281282
} else {
282283
eprintln!("[SKIP] no_sysroot tests");
283284
}
@@ -309,6 +310,7 @@ pub(crate) fn run_tests(
309310

310311
if run_base_sysroot {
311312
runner.run_testsuite(BASE_SYSROOT_SUITE);
313+
super::time("Ran testsuite base_sysroot");
312314
} else {
313315
eprintln!("[SKIP] base_sysroot tests");
314316
}
@@ -318,6 +320,7 @@ pub(crate) fn run_tests(
318320
// projects. Changing the code to fix them is not worth it, so just silence all lints.
319321
runner.target_compiler.rustflags.push("--cap-lints=allow".to_owned());
320322
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
323+
super::time("Ran testsuite extended_sysroot");
321324
} else {
322325
eprintln!("[SKIP] extended_sysroot tests");
323326
}
@@ -424,6 +427,8 @@ impl<'a> TestRunner<'a> {
424427
spawn_and_wait(jit_cmd);
425428
}
426429
}
430+
431+
super::time(&format!(" Ran test {config}"));
427432
}
428433
}
429434

0 commit comments

Comments
 (0)