Skip to content

Add profiler to bootstrap command #143525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::fs::{self, OpenOptions};
use std::io::{self, BufRead, BufReader, IsTerminal, Write};
use std::str::FromStr;
use std::time::Instant;
use std::{env, process};

use bootstrap::{
Expand All @@ -17,11 +18,17 @@ use bootstrap::{
#[cfg(feature = "tracing")]
use tracing::instrument;

fn is_bootstrap_profiling_enabled() -> bool {
env::var("BOOTSTRAP_PROFILE").is_ok_and(|v| v == "1")
}

#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))]
fn main() {
#[cfg(feature = "tracing")]
let _guard = setup_tracing();

let start_time = Instant::now();

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

if Flags::try_parse_verbose_help(&args) {
Expand Down Expand Up @@ -96,7 +103,8 @@ fn main() {
let out_dir = config.out.clone();

debug!("creating new build based on config");
Build::new(config).build();
let mut build = Build::new(config);
build.build();

if suggest_setup {
println!("WARNING: you have not made a `bootstrap.toml`");
Expand Down Expand Up @@ -147,6 +155,10 @@ fn main() {
t!(file.write_all(lines.join("\n").as_bytes()));
}
}

if is_bootstrap_profiling_enabled() {
build.report_summary(start_time);
}
}

fn check_version(config: &Config) -> Option<String> {
Expand Down Expand Up @@ -226,7 +238,7 @@ fn setup_tracing() -> impl Drop {
let mut chrome_layer = tracing_chrome::ChromeLayerBuilder::new().include_args(true);

// Writes the Chrome profile to trace-<unix-timestamp>.json if enabled
if !env::var("BOOTSTRAP_PROFILE").is_ok_and(|v| v == "1") {
if !is_bootstrap_profiling_enabled() {
chrome_layer = chrome_layer.writer(io::sink());
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ pub fn stream_cargo(
}

// Make sure Cargo actually succeeded after we read all of its stdout.
let status = t!(streaming_command.wait());
let status = t!(streaming_command.wait(&builder.config.exec_ctx));
if builder.is_verbose() && !status.success() {
eprintln!(
"command did not execute successfully: {cmd:?}\n\
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::sync::OnceLock;
use std::time::SystemTime;
use std::time::{Instant, SystemTime};
use std::{env, fs, io, str};

use build_helper::ci::gha;
Expand Down Expand Up @@ -1928,6 +1928,10 @@ to download LLVM rather than building it.
pub fn exec_ctx(&self) -> &ExecutionContext {
&self.config.exec_ctx
}

pub fn report_summary(&self, start_time: Instant) {
self.config.exec_ctx.profiler().report_summary(start_time);
}
}

impl AsRef<ExecutionContext> for Build {
Expand Down
Loading
Loading