Skip to content

Commit e5e1571

Browse files
committed
Add export of bootstrap tracing to Chrome events
1 parent 134b445 commit e5e1571

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
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
}

0 commit comments

Comments
 (0)