Skip to content

Commit 52f09c9

Browse files
committed
perf: Improve --profile instrumentation coverage to account for full wall-clock time
The CPU profile previously captured only 204ms of a 1051ms run because chrome tracing was enabled too late (after config resolution) and many key functions lacked instrumentation. This moves tracing enablement earlier and adds #[tracing::instrument] to the uninstrumented gaps.
1 parent 9399811 commit 52f09c9

File tree

9 files changed

+20
-6
lines changed

9 files changed

+20
-6
lines changed

crates/turborepo-lib/src/cli/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ fn get_command(cli_args: &mut Args) -> Result<Command, Error> {
12921292
///
12931293
/// returns: Result<Payload, Error>
12941294
#[tokio::main]
1295+
#[tracing::instrument(skip_all)]
12951296
pub async fn run(
12961297
repo_state: Option<RepoState>,
12971298
#[allow(unused_variables)] logger: &TurboSubscriber,
@@ -1586,6 +1587,13 @@ pub async fn run(
15861587
let event = CommandEventBuilder::new("run").with_parent(&root_telemetry);
15871588
event.track_call();
15881589

1590+
// Enable chrome tracing before any real work so that config
1591+
// resolution and CommandBase construction are captured.
1592+
let profile_file = run_args.profile_file_and_include_args();
1593+
if let Some((ref file_path, include_args)) = profile_file {
1594+
let _ = logger.enable_chrome_tracing(file_path, include_args);
1595+
}
1596+
15891597
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config)?;
15901598
event.track_ui_mode(base.opts.run_opts.ui_mode);
15911599

@@ -1594,12 +1602,6 @@ pub async fn run(
15941602
return Ok(1);
15951603
}
15961604

1597-
let profile_file = run_args.profile_file_and_include_args();
1598-
if let Some((ref file_path, include_args)) = profile_file {
1599-
// TODO: Do we want to handle the result / error?
1600-
let _ = logger.enable_chrome_tracing(file_path, include_args);
1601-
}
1602-
16031605
run_args.track(&event);
16041606
let exit_code = run::run(base, event).await.inspect(|code| {
16051607
if *code != 0 {

crates/turborepo-lib/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct CommandBase {
4545
}
4646

4747
impl CommandBase {
48+
#[tracing::instrument(skip_all)]
4849
pub fn new(
4950
args: Args,
5051
repo_root: AbsoluteSystemPathBuf,
@@ -76,6 +77,7 @@ impl CommandBase {
7677
}
7778
}
7879

80+
#[tracing::instrument(skip_all)]
7981
pub fn load_config(
8082
repo_root: &AbsoluteSystemPath,
8183
args: &Args,

crates/turborepo-lib/src/commands/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use turborepo_ui::sender::UISender;
77

88
use crate::{commands::CommandBase, run, run::builder::RunBuilder};
99

10+
#[tracing::instrument(skip_all)]
1011
pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i32, run::Error> {
1112
let signal = get_signal()?;
1213
let handler = SignalHandler::new(signal);

crates/turborepo-lib/src/microfrontends.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct ConfigInfo {
3030

3131
impl MicrofrontendsConfigs {
3232
/// Constructs a collection of configurations from disk
33+
#[tracing::instrument(skip_all)]
3334
pub fn from_disk(
3435
repo_root: &AbsoluteSystemPath,
3536
package_graph: &PackageGraph,

crates/turborepo-lib/src/run/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct RunBuilder {
6363
}
6464

6565
impl RunBuilder {
66+
#[tracing::instrument(skip_all)]
6667
pub fn new(base: CommandBase) -> Result<Self, Error> {
6768
let api_client = base.api_client()?;
6869

@@ -405,6 +406,7 @@ impl RunBuilder {
405406
})
406407
}
407408

409+
#[tracing::instrument(skip_all)]
408410
fn build_engine<'a>(
409411
&self,
410412
pkg_dep_graph: &PackageGraph,

crates/turborepo-lib/src/run/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ impl Run {
573573
info!("Proxy shutdown complete, proceeding with visitor cleanup");
574574
}
575575

576+
#[instrument(skip_all)]
576577
async fn execute_visitor(
577578
&self,
578579
ui_sender: Option<UISender>,
@@ -735,6 +736,7 @@ impl Run {
735736
Ok(exit_code)
736737
}
737738

739+
#[instrument(skip_all)]
738740
pub async fn run(&self, ui_sender: Option<UISender>, is_watch: bool) -> Result<i32, Error> {
739741
let proxy_shutdown = self.start_proxy_if_needed().await?;
740742
self.setup_cache_shutdown_handler();

crates/turborepo-repository/src/inference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl RepoState {
7373
/// * `reference_dir`: Turbo's invocation directory
7474
///
7575
/// returns: Result<RepoState, Error>
76+
#[tracing::instrument(skip_all)]
7677
pub fn infer(reference_dir: &AbsoluteSystemPath) -> Result<Self, Error> {
7778
reference_dir
7879
.ancestors()

crates/turborepo-run-summary/src/tracker.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ impl<'a> RunSummary<'a> {
343343
}
344344
}
345345

346+
#[tracing::instrument(skip_all)]
346347
fn close_dry_run(
347348
&mut self,
348349
pkg_dep_graph: &PackageGraph,
@@ -358,6 +359,7 @@ impl<'a> RunSummary<'a> {
358359
self.format_and_print_text(pkg_dep_graph, ui)
359360
}
360361

362+
#[tracing::instrument(skip_all)]
361363
fn format_and_print_text(
362364
&mut self,
363365
pkg_dep_graph: &PackageGraph,

crates/turborepo-task-executor/src/exec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ pub struct DryRunExecutor<H> {
603603
}
604604

605605
impl<H: HashTrackerProvider> DryRunExecutor<H> {
606+
#[tracing::instrument(skip_all, fields(task = %self.task_id))]
606607
pub async fn execute_dry_run(&self, tracker: TaskTracker<()>) -> Result<(), InternalError> {
607608
if let Ok(Some(status)) = self.task_cache.exists().await {
608609
self.hash_tracker

0 commit comments

Comments
 (0)