Skip to content

Commit 2e1a532

Browse files
committed
bootstrap: add more logging
1 parent 71703bb commit 2e1a532

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

src/bootstrap/src/bin/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bootstrap::{
1616
};
1717
use build_helper::ci::CiEnv;
1818
#[cfg(feature = "tracing")]
19-
use tracing::{instrument, trace};
19+
use tracing::{debug, instrument};
2020

2121
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))]
2222
fn main() {
@@ -29,7 +29,11 @@ fn main() {
2929
return;
3030
}
3131

32+
#[cfg(feature = "tracing")]
33+
debug!("parsing flags");
3234
let flags = Flags::parse(&args);
35+
#[cfg(feature = "tracing")]
36+
debug!("parsing config based on flags");
3337
let config = Config::parse(flags);
3438

3539
let mut build_lock;
@@ -91,6 +95,8 @@ fn main() {
9195
let dump_bootstrap_shims = config.dump_bootstrap_shims;
9296
let out_dir = config.out.clone();
9397

98+
#[cfg(feature = "tracing")]
99+
debug!("creating new build based on config");
94100
Build::new(config).build();
95101

96102
if suggest_setup {

src/bootstrap/src/core/config/config.rs

+41
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use build_helper::exit;
1818
use build_helper::git::{GitConfig, get_closest_merge_commit, output_result};
1919
use serde::{Deserialize, Deserializer};
2020
use serde_derive::Deserialize;
21+
#[cfg(feature = "tracing")]
22+
use tracing::{instrument, span};
2123

2224
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
2325
use crate::core::build_steps::llvm;
@@ -1227,7 +1229,14 @@ define_config! {
12271229
}
12281230

12291231
impl Config {
1232+
#[cfg_attr(
1233+
feature = "tracing",
1234+
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::default_opts")
1235+
)]
12301236
pub fn default_opts() -> Config {
1237+
#[cfg(feature = "tracing")]
1238+
span!(target: "CONFIG_HANDLING", tracing::Level::TRACE, "constructing default config");
1239+
12311240
Config {
12321241
bypass_bootstrap_lock: false,
12331242
llvm_optimize: true,
@@ -1311,10 +1320,23 @@ impl Config {
13111320
})
13121321
}
13131322

1323+
#[cfg_attr(
1324+
feature = "tracing",
1325+
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::parse", skip_all)
1326+
)]
13141327
pub fn parse(flags: Flags) -> Config {
13151328
Self::parse_inner(flags, Self::get_toml)
13161329
}
13171330

1331+
#[cfg_attr(
1332+
feature = "tracing",
1333+
instrument(
1334+
target = "CONFIG_HANDLING",
1335+
level = "trace",
1336+
name = "Config::parse_inner",
1337+
skip_all
1338+
)
1339+
)]
13181340
pub(crate) fn parse_inner(
13191341
mut flags: Flags,
13201342
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
@@ -1323,6 +1345,17 @@ impl Config {
13231345

13241346
// Set flags.
13251347
config.paths = std::mem::take(&mut flags.paths);
1348+
1349+
#[cfg(feature = "tracing")]
1350+
span!(
1351+
target: "CONFIG_HANDLING",
1352+
tracing::Level::TRACE,
1353+
"collecting paths and path exclusions",
1354+
"flags.paths" = ?flags.paths,
1355+
"flags.skip" = ?flags.skip,
1356+
"flags.exclude" = ?flags.exclude
1357+
);
1358+
13261359
config.skip = flags
13271360
.skip
13281361
.into_iter()
@@ -1339,6 +1372,14 @@ impl Config {
13391372
})
13401373
.collect();
13411374

1375+
#[cfg(feature = "tracing")]
1376+
span!(
1377+
target: "CONFIG_HANDLING",
1378+
tracing::Level::TRACE,
1379+
"normalizing and combining `flag.skip`/`flag.exclude` paths",
1380+
"config.skip" = ?config.skip,
1381+
);
1382+
13421383
config.include_default_paths = flags.include_default_paths;
13431384
config.rustc_error_format = flags.rustc_error_format;
13441385
config.json_output = flags.json_output;

src/bootstrap/src/core/config/flags.rs

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use std::path::{Path, PathBuf};
77

88
use clap::{CommandFactory, Parser, ValueEnum};
9+
#[cfg(feature = "tracing")]
10+
use tracing::instrument;
911

1012
use crate::core::build_steps::setup::Profile;
1113
use crate::core::builder::{Builder, Kind};
@@ -211,6 +213,10 @@ impl Flags {
211213
}
212214
}
213215

216+
#[cfg_attr(
217+
feature = "tracing",
218+
instrument(level = "trace", name = "Flags::parse", skip_all, fields(args = ?args))
219+
)]
214220
pub fn parse(args: &[String]) -> Self {
215221
Flags::parse_from(normalize_args(args))
216222
}

src/bootstrap/src/lib.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use std::{env, fs, io, str};
2828
use build_helper::ci::gha;
2929
use build_helper::exit;
3030
use termcolor::{ColorChoice, StandardStream, WriteColor};
31+
#[cfg(feature = "tracing")]
32+
use tracing::{debug, instrument, span, trace};
3133
use utils::build_stamp::BuildStamp;
3234
use utils::channel::GitInfo;
3335

@@ -537,14 +539,25 @@ impl Build {
537539
}
538540

539541
/// Executes the entire build, as configured by the flags and configuration.
542+
#[cfg_attr(feature = "tracing", instrument(level = "debug", name = "Build::build", skip_all))]
540543
pub fn build(&mut self) {
544+
#[cfg(feature = "tracing")]
545+
trace!("setting up job management");
541546
unsafe {
542547
crate::utils::job::setup(self);
543548
}
544549

550+
#[cfg(feature = "tracing")]
551+
trace!("downloading rustfmt early");
552+
545553
// Download rustfmt early so that it can be used in rust-analyzer configs.
546554
let _ = &builder::Builder::new(self).initial_rustfmt();
547555

556+
#[cfg(feature = "tracing")]
557+
let hardcoded_span =
558+
span!(tracing::Level::DEBUG, "handling hardcoded subcommands (Format, Suggest, Perf)")
559+
.entered();
560+
548561
// hardcoded subcommands
549562
match &self.config.cmd {
550563
Subcommand::Format { check, all } => {
@@ -561,25 +574,50 @@ impl Build {
561574
Subcommand::Perf { .. } => {
562575
return core::build_steps::perf::perf(&builder::Builder::new(self));
563576
}
564-
_ => (),
577+
_cmd => {
578+
#[cfg(feature = "tracing")]
579+
debug!(cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling");
580+
}
565581
}
566582

583+
#[cfg(feature = "tracing")]
584+
drop(hardcoded_span);
585+
#[cfg(feature = "tracing")]
586+
debug!("handling subcommand normally");
587+
567588
if !self.config.dry_run() {
589+
#[cfg(feature = "tracing")]
590+
let _real_run_span = span!(tracing::Level::DEBUG, "executing real run").entered();
591+
568592
{
593+
#[cfg(feature = "tracing")]
594+
let _sanity_check_span =
595+
span!(tracing::Level::DEBUG, "(1) executing dry-run sanity-check").entered();
596+
569597
// We first do a dry-run. This is a sanity-check to ensure that
570598
// steps don't do anything expensive in the dry-run.
571599
self.config.dry_run = DryRun::SelfCheck;
572600
let builder = builder::Builder::new(self);
573601
builder.execute_cli();
574602
}
603+
604+
#[cfg(feature = "tracing")]
605+
let _actual_run_span =
606+
span!(tracing::Level::DEBUG, "(2) executing actual run").entered();
575607
self.config.dry_run = DryRun::Disabled;
576608
let builder = builder::Builder::new(self);
577609
builder.execute_cli();
578610
} else {
611+
#[cfg(feature = "tracing")]
612+
let _dry_run_span = span!(tracing::Level::DEBUG, "executing dry run").entered();
613+
579614
let builder = builder::Builder::new(self);
580615
builder.execute_cli();
581616
}
582617

618+
#[cfg(feature = "tracing")]
619+
debug!("checking for postponed test failures from `test --no-fail-fast`");
620+
583621
// Check for postponed failures from `test --no-fail-fast`.
584622
let failures = self.delayed_failures.borrow();
585623
if failures.len() > 0 {

0 commit comments

Comments
 (0)