Skip to content

Commit f265550

Browse files
committed
[WIP] Add timing messages
1 parent f19415e commit f265550

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
@@ -38,6 +38,8 @@ pub(crate) fn build_backend(
3838
eprintln!("[BUILD] rustc_codegen_cranelift");
3939
crate::utils::spawn_and_wait(cmd);
4040

41+
super::time("Built backend");
42+
4143
CG_CLIF
4244
.target_dir(dirs)
4345
.join(&bootstrap_host_compiler.triple)

build_system/build_sysroot.rs

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

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

3436
let cg_clif_dylib_path = match cg_clif_dylib_src {
@@ -49,6 +51,8 @@ pub(crate) fn build_sysroot(
4951
CodegenBackend::Builtin(name) => CodegenBackend::Builtin(name.clone()),
5052
};
5153

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

90+
super::time(" Built wrappers");
91+
8492
let host = build_sysroot_for_triple(
8593
dirs,
8694
bootstrap_host_compiler.clone(),
@@ -133,6 +141,9 @@ pub(crate) fn build_sysroot(
133141
if !is_native {
134142
target_compiler.set_cross_linker_and_runner();
135143
}
144+
145+
super::time("Built sysroot");
146+
136147
target_compiler
137148
}
138149

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
}
@@ -199,6 +214,8 @@ fn main() {
199214
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
200215
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
201216

217+
time("Inited");
218+
202219
let cg_clif_dylib = if let Some(name) = use_backend {
203220
CodegenBackend::Builtin(name)
204221
} else {

build_system/tests.rs

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

271271
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
272272
runner.run_testsuite(NO_SYSROOT_SUITE);
273+
super::time("Ran testsuite no_sysroot");
273274
} else {
274275
eprintln!("[SKIP] no_sysroot tests");
275276
}
@@ -300,6 +301,7 @@ pub(crate) fn run_tests(
300301

301302
if run_base_sysroot {
302303
runner.run_testsuite(BASE_SYSROOT_SUITE);
304+
super::time("Ran testsuite base_sysroot");
303305
} else {
304306
eprintln!("[SKIP] base_sysroot tests");
305307
}
@@ -309,6 +311,7 @@ pub(crate) fn run_tests(
309311
// projects. Changing the code to fix them is not worth it, so just silence all lints.
310312
runner.target_compiler.rustflags.push("--cap-lints=allow".to_owned());
311313
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
314+
super::time("Ran testsuite extended_sysroot");
312315
} else {
313316
eprintln!("[SKIP] extended_sysroot tests");
314317
}
@@ -415,6 +418,8 @@ impl<'a> TestRunner<'a> {
415418
spawn_and_wait(jit_cmd);
416419
}
417420
}
421+
422+
super::time(&format!(" Ran test {config}"));
418423
}
419424
}
420425

0 commit comments

Comments
 (0)