Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 447a6a0

Browse files
committed
Add export of bootstrap tracing to Chrome events
1 parent d7eca8a commit 447a6a0

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

src/bootstrap/Cargo.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ dependencies = [
5959
"termcolor",
6060
"toml",
6161
"tracing",
62+
"tracing-chrome",
6263
"tracing-subscriber",
6364
"tracing-tree",
6465
"walkdir",
@@ -727,6 +728,17 @@ dependencies = [
727728
"syn",
728729
]
729730

731+
[[package]]
732+
name = "tracing-chrome"
733+
version = "0.7.2"
734+
source = "registry+https://github.com/rust-lang/crates.io-index"
735+
checksum = "bf0a738ed5d6450a9fb96e86a23ad808de2b727fd1394585da5cdd6788ffe724"
736+
dependencies = [
737+
"serde_json",
738+
"tracing-core",
739+
"tracing-subscriber",
740+
]
741+
730742
[[package]]
731743
name = "tracing-core"
732744
version = "0.1.33"

src/bootstrap/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default-run = "bootstrap"
77

88
[features]
99
build-metrics = ["sysinfo"]
10-
tracing = ["dep:tracing", "dep:tracing-subscriber", "dep:tracing-tree"]
10+
tracing = ["dep:tracing", "dep:tracing-chrome", "dep:tracing-subscriber", "dep:tracing-tree"]
1111

1212
[lib]
1313
path = "src/lib.rs"
@@ -67,6 +67,7 @@ sysinfo = { version = "0.33.0", default-features = false, optional = true, featu
6767

6868
# Dependencies needed by the `tracing` feature
6969
tracing = { version = "0.1", optional = true, features = ["attributes"] }
70+
tracing-chrome = { version = "0.7", optional = true }
7071
tracing-subscriber = { version = "0.3", optional = true, features = ["env-filter", "fmt", "registry", "std"] }
7172
tracing-tree = { version = "0.4.0", optional = true }
7273

src/bootstrap/src/bin/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing::instrument;
2121
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))]
2222
fn main() {
2323
#[cfg(feature = "tracing")]
24-
setup_tracing();
24+
let _guard = setup_tracing();
2525

2626
let args = env::args().skip(1).collect::<Vec<_>>();
2727

@@ -210,15 +210,25 @@ fn check_version(config: &Config) -> Option<String> {
210210
// - `tracing`'s `#[instrument(..)]` macro will need to be gated like `#![cfg_attr(feature =
211211
// "tracing", instrument(..))]`.
212212
#[cfg(feature = "tracing")]
213-
fn setup_tracing() {
213+
fn setup_tracing() -> impl Drop {
214214
use tracing_subscriber::EnvFilter;
215215
use tracing_subscriber::layer::SubscriberExt;
216216

217217
let filter = EnvFilter::from_env("BOOTSTRAP_TRACING");
218218
// cf. <https://docs.rs/tracing-tree/latest/tracing_tree/struct.HierarchicalLayer.html>.
219219
let layer = tracing_tree::HierarchicalLayer::default().with_targets(true).with_indent_amount(2);
220220

221-
let registry = tracing_subscriber::registry().with(filter).with(layer);
221+
let mut chrome_layer = tracing_chrome::ChromeLayerBuilder::new().include_args(true);
222+
223+
// Writes the Chrome profile to trace-<unix-timestamp>.json if enabled
224+
if !env::var("BOOTSTRAP_PROFILE").is_ok_and(|v| v == "1") {
225+
chrome_layer = chrome_layer.writer(io::sink());
226+
}
227+
228+
let (chrome_layer, _guard) = chrome_layer.build();
229+
230+
let registry = tracing_subscriber::registry().with(filter).with(layer).with(chrome_layer);
222231

223232
tracing::subscriber::set_global_default(registry).unwrap();
233+
_guard
224234
}

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::utils::exec::command;
3030
use crate::utils::helpers::{
3131
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3232
};
33-
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace_cmd};
33+
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode};
3434

3535
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3636
pub struct Std {
@@ -2235,7 +2235,8 @@ pub fn stream_cargo(
22352235
) -> bool {
22362236
let mut cmd = cargo.into_cmd();
22372237

2238-
let _run_span = trace_cmd!(cmd);
2238+
#[cfg(feature = "tracing")]
2239+
let _run_span = crate::trace_cmd!(cmd);
22392240

22402241
let cargo = cmd.as_command_mut();
22412242
// Instruct Cargo to give us json messages on stdout, critically leaving

src/bootstrap/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ impl Build {
905905
return CommandOutput::default();
906906
}
907907

908+
#[cfg(feature = "tracing")]
908909
let _run_span = trace_cmd!(command);
909910

910911
let created_at = command.get_created_location();

src/bootstrap/src/utils/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl FormatShortCmd for Command {
347347
fn format_short_cmd(&self) -> String {
348348
let program = Path::new(self.get_program());
349349
let mut line = vec![program.file_name().unwrap().to_str().unwrap()];
350-
line.extend(self.get_args().into_iter().map(|arg| arg.to_str().unwrap()));
350+
line.extend(self.get_args().map(|arg| arg.to_str().unwrap()));
351351
line.join(" ")
352352
}
353353
}

src/bootstrap/src/utils/helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::{env, fs, io, str};
1313
use build_helper::util::fail;
1414
use object::read::archive::ArchiveFile;
1515

16+
use crate::LldMode;
1617
use crate::core::builder::Builder;
1718
use crate::core::config::{Config, TargetSelection};
1819
use crate::utils::exec::{BootstrapCommand, command};
1920
pub use crate::utils::shared_helpers::{dylib_path, dylib_path_var};
20-
use crate::{LldMode, trace_cmd};
2121

2222
#[cfg(test)]
2323
mod tests;
@@ -265,7 +265,8 @@ pub fn make(host: &str) -> PathBuf {
265265

266266
#[track_caller]
267267
pub fn output(cmd: &mut Command) -> String {
268-
let _run_span = trace_cmd!(cmd);
268+
#[cfg(feature = "tracing")]
269+
let _run_span = crate::trace_cmd!(cmd);
269270

270271
let output = match cmd.stderr(Stdio::inherit()).output() {
271272
Ok(status) => status,

src/bootstrap/src/utils/tracing.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ macro_rules! error {
5252
macro_rules! trace_cmd {
5353
($cmd:expr) => {
5454
{
55-
#[allow(unused)]
5655
use $crate::utils::exec::FormatShortCmd;
5756

58-
#[cfg(feature = "tracing")]
5957
::tracing::span!(
6058
target: "COMMAND",
6159
::tracing::Level::TRACE,

0 commit comments

Comments
 (0)