Skip to content

Commit 345f7a7

Browse files
feat: add new cli flag --fair-sched and support for experimental flags
1 parent d3e9ba6 commit 345f7a7

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/cli/experimental.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use crate::local_logger::icons::Icon;
2+
use clap::Args;
3+
use console::style;
4+
5+
/// Experimental flags that may change or be removed without notice.
6+
///
7+
/// These flags are under active development and their behavior is not guaranteed
8+
/// to remain stable across releases.
9+
#[derive(Args, Debug, Clone)]
10+
pub struct ExperimentalArgs {
11+
/// Enable valgrind's --fair-sched option.
12+
#[arg(
13+
long,
14+
default_value_t = false,
15+
help_heading = "Experimental",
16+
env = "CODSPEED_EXPERIMENTAL_FAIR_SCHED"
17+
)]
18+
pub experimental_fair_sched: bool,
19+
}
20+
21+
impl ExperimentalArgs {
22+
/// Returns the names of all experimental flags that were explicitly set by the user.
23+
pub fn active_flags(&self) -> Vec<&'static str> {
24+
let mut flags = Vec::new();
25+
if self.experimental_fair_sched {
26+
flags.push("--experimental-fair-sched");
27+
}
28+
flags
29+
}
30+
31+
/// If any experimental flags are active, prints a warning to stderr.
32+
pub fn warn_if_active(&self) {
33+
let flags = self.active_flags();
34+
if flags.is_empty() {
35+
return;
36+
}
37+
38+
let flag_list = flags
39+
.iter()
40+
.map(|f| style(*f).bold().to_string())
41+
.collect::<Vec<_>>()
42+
.join(", ");
43+
44+
eprintln!(
45+
"\n {} Experimental flags enabled: {}\n \
46+
These may change or be removed without notice.\n \
47+
Share feedback at {}.\n",
48+
style(Icon::Warning.to_string()).yellow(),
49+
flag_list,
50+
style("https://github.com/CodSpeedHQ/codspeed/issues").underlined(),
51+
);
52+
}
53+
}

src/cli/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod auth;
22
pub(crate) mod exec;
3+
pub(crate) mod experimental;
34
pub(crate) mod run;
45
mod setup;
56
mod shared;
@@ -148,6 +149,7 @@ pub async fn run() -> Result<()> {
148149

149150
match cli.command {
150151
Commands::Run(args) => {
152+
args.shared.experimental.warn_if_active();
151153
run::run(
152154
*args,
153155
&api_client,
@@ -158,6 +160,7 @@ pub async fn run() -> Result<()> {
158160
.await?
159161
}
160162
Commands::Exec(args) => {
163+
args.shared.experimental.warn_if_active();
161164
exec::run(
162165
*args,
163166
&api_client,

src/cli/run/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl RunArgs {
4949
/// Constructs a new `RunArgs` with default values for testing purposes
5050
pub fn test() -> Self {
5151
use super::PerfRunArgs;
52+
use super::experimental::ExperimentalArgs;
5253
use crate::RunnerMode;
5354

5455
Self {
@@ -72,6 +73,9 @@ impl RunArgs {
7273
enable_perf: false,
7374
perf_unwinding_mode: None,
7475
},
76+
experimental: ExperimentalArgs {
77+
experimental_fair_sched: false,
78+
},
7579
},
7680
instruments: vec![],
7781
mongo_uri_env_name: None,

src/cli/shared.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::experimental::ExperimentalArgs;
12
use crate::VERSION;
23
use crate::executor::config::SimulationTool;
34
use crate::local_logger::CODSPEED_U8_COLOR_CODE;
@@ -116,6 +117,9 @@ pub struct ExecAndRunSharedArgs {
116117

117118
#[command(flatten)]
118119
pub perf_run_args: PerfRunArgs,
120+
121+
#[command(flatten)]
122+
pub experimental: ExperimentalArgs,
119123
}
120124

121125
impl ExecAndRunSharedArgs {

0 commit comments

Comments
 (0)