diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 61dfc2d4911ec..07f6acd13ae92 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -1,7 +1,10 @@ use std::{backtrace, backtrace::Backtrace, env, io, mem, process}; use camino::{Utf8Path, Utf8PathBuf}; -use clap::{ArgAction, ArgGroup, CommandFactory, Parser, Subcommand, ValueEnum}; +use clap::{ + builder::NonEmptyStringValueParser, ArgAction, ArgGroup, CommandFactory, Parser, Subcommand, + ValueEnum, +}; use clap_complete::{generate, Shell}; pub use error::Error; use serde::{Deserialize, Serialize}; @@ -569,8 +572,13 @@ pub struct RunArgs { /// File to write turbo's performance profile output into. /// You can load the file up in chrome://tracing to see /// which parts of your build were slow. - #[clap(long)] + #[clap(long, value_parser=NonEmptyStringValueParser::new(), conflicts_with = "anon_profile")] pub profile: Option, + /// File to write turbo's performance profile output into. + /// All identifying data omitted from the profile. + #[serde(skip)] + #[clap(long, value_parser=NonEmptyStringValueParser::new(), conflicts_with = "profile")] + pub anon_profile: Option, /// Ignore the local filesystem cache for all tasks. Only /// allow reading and caching artifacts using the remote cache. #[clap(long, env = "TURBO_REMOTE_ONLY", value_name = "BOOL", action = ArgAction::Set, default_value = "false", default_missing_value = "true", num_args = 0..=1)] @@ -626,6 +634,15 @@ impl RunArgs { (true, true) => unreachable!(), // guaranteed by mutually exclusive `ArgGroup` } } + + pub fn profile_file_and_include_args(&self) -> Option<(&str, bool)> { + match (self.profile.as_deref(), self.anon_profile.as_deref()) { + (Some(file), None) => Some((file, true)), + (None, Some(file)) => Some((file, false)), + (Some(_), Some(_)) => unreachable!(), + (None, None) => None, + } + } } #[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Serialize)] @@ -849,9 +866,10 @@ pub async fn run( if args.tasks.is_empty() { return Err(Error::NoTasks(backtrace::Backtrace::capture())); } - if let Some(file_path) = &args.profile { + + if let Some((file_path, include_args)) = args.profile_file_and_include_args() { // TODO: Do we want to handle the result / error? - let _ = logger.enable_chrome_tracing(file_path); + let _ = logger.enable_chrome_tracing(file_path, include_args); } let base = CommandBase::new(cli_args.clone(), repo_root, version, ui); @@ -1989,4 +2007,21 @@ mod test { assert!(Args::try_parse_from(["turbo", "build", "--go-fallback"]).is_ok(),); assert!(Args::try_parse_from(["turbo", "build", "--remote-cache-read-only",]).is_ok(),); } + + #[test] + fn test_profile_usage() { + assert!(Args::try_parse_from(["turbo", "build", "--profile", ""]).is_err()); + assert!(Args::try_parse_from(["turbo", "build", "--anon-profile", ""]).is_err()); + assert!(Args::try_parse_from(["turbo", "build", "--profile", "foo.json"]).is_ok()); + assert!(Args::try_parse_from(["turbo", "build", "--anon-profile", "foo.json"]).is_ok()); + assert!(Args::try_parse_from([ + "turbo", + "build", + "--profile", + "foo.json", + "--anon-profile", + "bar.json" + ]) + .is_err()); + } } diff --git a/crates/turborepo-lib/src/tracing.rs b/crates/turborepo-lib/src/tracing.rs index fd9aee3514345..6a23796d30b6b 100644 --- a/crates/turborepo-lib/src/tracing.rs +++ b/crates/turborepo-lib/src/tracing.rs @@ -189,10 +189,14 @@ impl TurboSubscriber { /// Enables chrome tracing. #[tracing::instrument(skip(self, to_file))] - pub fn enable_chrome_tracing>(&self, to_file: P) -> Result<(), Error> { + pub fn enable_chrome_tracing>( + &self, + to_file: P, + include_args: bool, + ) -> Result<(), Error> { let (layer, guard) = tracing_chrome::ChromeLayerBuilder::new() .file(to_file) - .include_args(true) + .include_args(include_args) .include_locations(true) .build(); diff --git a/turborepo-tests/integration/tests/no-args.t b/turborepo-tests/integration/tests/no-args.t index f652816e6943c..e5cac6a915e46 100644 --- a/turborepo-tests/integration/tests/no-args.t +++ b/turborepo-tests/integration/tests/no-args.t @@ -85,6 +85,8 @@ Make sure exit code is 2 when no args are passed Execute all tasks in parallel --profile File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow + --anon-profile + File to write turbo's performance profile output into. All identifying data omitted from the profile --remote-only [] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache [env: TURBO_REMOTE_ONLY=] [default: false] [possible values: true, false] --remote-cache-read-only [] diff --git a/turborepo-tests/integration/tests/turbo-help.t b/turborepo-tests/integration/tests/turbo-help.t index 99c08cdda1048..8a62f2199ce3c 100644 --- a/turborepo-tests/integration/tests/turbo-help.t +++ b/turborepo-tests/integration/tests/turbo-help.t @@ -85,6 +85,8 @@ Test help flag Execute all tasks in parallel --profile File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow + --anon-profile + File to write turbo's performance profile output into. All identifying data omitted from the profile --remote-only [] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache [env: TURBO_REMOTE_ONLY=] [default: false] [possible values: true, false] --remote-cache-read-only [] @@ -186,6 +188,8 @@ Test help flag Execute all tasks in parallel --profile File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow + --anon-profile + File to write turbo's performance profile output into. All identifying data omitted from the profile --remote-only [] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache [env: TURBO_REMOTE_ONLY=] [default: false] [possible values: true, false] --remote-cache-read-only []