Skip to content

Commit ac26174

Browse files
committed
--wip-- [skip ci]
1 parent bebfdac commit ac26174

12 files changed

Lines changed: 81 additions & 71 deletions

File tree

src/app.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
22
api_client::CodSpeedAPIClient, auth, local_logger::CODSPEED_U8_COLOR_CODE, prelude::*, run,
3+
setup,
34
};
45
use clap::{
56
builder::{styling, Styles},
@@ -37,8 +38,10 @@ pub struct Cli {
3738
enum Commands {
3839
/// Run the bench command and upload the results to CodSpeed
3940
Run(run::RunArgs),
40-
/// Commands related to authentication with CodSpeed
41+
/// Manage the CLI authentication state
4142
Auth(auth::AuthArgs),
43+
/// Setup the CLI environment
44+
Setup(setup::SetupArgs),
4245
}
4346

4447
pub async fn run() -> Result<()> {
@@ -48,6 +51,7 @@ pub async fn run() -> Result<()> {
4851
match cli.command {
4952
Commands::Run(args) => run::run(args, &api_client).await?,
5053
Commands::Auth(args) => auth::run(args, &api_client).await?,
54+
Commands::Setup(args) => setup::setup(args).await?,
5155
}
5256
Ok(())
5357
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod logger;
77
mod prelude;
88
mod request_client;
99
mod run;
10+
mod setup;
1011

1112
use console::style;
1213
use lazy_static::lazy_static;

src/run/instruments/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ impl Instruments {
7878
}
7979
}
8080

81+
trait Instrument {
82+
async fn setup(&self) -> Result<()>;
83+
}
84+
8185
#[cfg(test)]
8286
mod tests {
8387
use super::*;

src/run/instruments/mongo_tracer.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
env::temp_dir,
23
io::Read,
34
path::{Path, PathBuf},
45
process::{Child, Command, Stdio},
@@ -13,7 +14,7 @@ use url::Url;
1314
use crate::prelude::*;
1415
use crate::run::helpers::get_env_variable;
1516

16-
use super::MongoDBConfig;
17+
use super::{Instrument, MongoDBConfig};
1718

1819
#[derive(Debug, PartialEq, Eq)]
1920
pub struct UserInput {
@@ -30,6 +31,39 @@ pub struct MongoTracer {
3031
user_input: Option<UserInput>,
3132
}
3233

34+
impl Instrument for MongoTracer {
35+
async fn setup(&self) -> Result<()> {
36+
install_mongodb_tracer().await
37+
}
38+
}
39+
40+
async fn install_mongodb_tracer() -> Result<()> {
41+
debug!("Installing mongodb-tracer");
42+
// TODO: release the tracer and update this url
43+
let installer_url = format!("https://codspeed-public-assets.s3.eu-west-1.amazonaws.com/mongo-tracer/{MONGODB_TRACER_VERSION}/cs-mongo-tracer-installer.sh");
44+
let installer_path = temp_dir().join("cs-mongo-tracer-installer.sh");
45+
download_file(
46+
&Url::parse(installer_url.as_str()).unwrap(),
47+
&installer_path,
48+
)
49+
.await?;
50+
51+
let output = Command::new("bash")
52+
.arg(installer_path.to_str().unwrap())
53+
.stdout(Stdio::piped())
54+
.stderr(Stdio::piped())
55+
.output()
56+
.map_err(|_| anyhow!("Failed to install mongo-tracer"))?;
57+
58+
if !output.status.success() {
59+
info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
60+
error!("stderr: {}", String::from_utf8_lossy(&output.stderr));
61+
bail!("Failed to install mongo-tracer");
62+
}
63+
64+
Ok(())
65+
}
66+
3367
/// TODO: This implementation is not optimal: full lines might get split in multiple chunks.
3468
/// This is not a problem for the current use case, as the tracer will be directly invoked as a .so library in the future,
3569
/// inheriting the current process' stdout/stderr.
@@ -44,7 +78,6 @@ fn dump_tracer_log(mut stream: impl Read) -> Result<()> {
4478
let buf = &buf[..num_read];
4579
debug!("[MONGO TRACER LOGS] {}", String::from_utf8_lossy(buf));
4680
}
47-
4881
Ok(())
4982
}
5083

src/run/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use run_environment::interfaces::RunEnvironment;
1010
use runner::get_run_data;
1111

1212
mod check_system;
13-
mod helpers;
13+
pub mod helpers;
1414
mod instruments;
1515
mod poll_results;
1616
pub mod run_environment;
@@ -120,14 +120,15 @@ pub async fn run(args: RunArgs, api_client: &CodSpeedAPIClient) -> Result<()> {
120120
let mode = runner::get_mode()?;
121121
let executor = runner::get_executor_from_mode(mode);
122122

123-
let run_data = get_run_data()?;
124-
125123
if !config.skip_setup {
126124
start_group!("Preparing the environment");
127-
executor.setup(&config, &system_info, &run_data).await?;
125+
executor.setup(&system_info).await?;
126+
info!("Environment ready");
128127
end_group!();
129128
}
130129

130+
let run_data = get_run_data()?;
131+
131132
start_opened_group!("Running the benchmarks");
132133

133134
// TODO: refactor and move directly in the Instruments struct as a `start` method

src/run/runner/executor.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ use async_trait::async_trait;
88
pub trait Executor {
99
fn name(&self) -> ExecutorName;
1010

11-
async fn setup(
12-
&self,
13-
config: &Config,
14-
system_info: &SystemInfo,
15-
run_data: &RunData,
16-
) -> Result<()>;
11+
async fn setup(&self, _system_info: &SystemInfo) -> Result<()> {
12+
Ok(())
13+
}
1714

1815
/// Runs the executor
1916
async fn run(

src/run/runner/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub fn get_executor_from_mode(mode: RunnerMode) -> Box<dyn Executor> {
6060
}
6161
}
6262

63+
pub fn get_all_executors() -> Vec<Box<dyn Executor>> {
64+
vec![Box::new(ValgrindExecutor), Box::new(WallTimeExecutor)]
65+
}
66+
6367
pub fn get_run_data() -> Result<RunData> {
6468
let profile_folder = create_profile_folder()?;
6569
Ok(RunData { profile_folder })

src/run/runner/valgrind/executor.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::run::runner::executor::Executor;
66
use crate::run::runner::{ExecutorName, RunData};
77
use crate::run::{check_system::SystemInfo, config::Config};
88

9-
use super::{helpers::perf_maps::harvest_perf_maps, measure, setup::setup};
9+
use super::setup::install_valgrind;
10+
use super::{helpers::perf_maps::harvest_perf_maps, measure};
1011

1112
pub struct ValgrindExecutor;
1213

@@ -16,14 +17,8 @@ impl Executor for ValgrindExecutor {
1617
ExecutorName::Valgrind
1718
}
1819

19-
async fn setup(
20-
&self,
21-
config: &Config,
22-
system_info: &SystemInfo,
23-
_run_data: &RunData,
24-
) -> Result<()> {
25-
setup(system_info, config).await?;
26-
20+
async fn setup(&self, system_info: &SystemInfo) -> Result<()> {
21+
install_valgrind(system_info).await?;
2722
Ok(())
2823
}
2924

src/run/runner/valgrind/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub mod executor;
2-
mod helpers;
2+
pub mod helpers;
33
mod measure;
44
mod setup;

src/run/runner/valgrind/setup.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn is_valgrind_installed() -> bool {
8383
}
8484
}
8585

86-
async fn install_valgrind(system_info: &SystemInfo) -> Result<()> {
86+
pub async fn install_valgrind(system_info: &SystemInfo) -> Result<()> {
8787
if is_valgrind_installed() {
8888
debug!("Valgrind is already installed with the correct version, skipping installation");
8989
return Ok(());
@@ -109,44 +109,6 @@ async fn install_valgrind(system_info: &SystemInfo) -> Result<()> {
109109
Ok(())
110110
}
111111

112-
async fn install_mongodb_tracer() -> Result<()> {
113-
debug!("Installing mongodb-tracer");
114-
// TODO: release the tracer and update this url
115-
let installer_url = format!("https://codspeed-public-assets.s3.eu-west-1.amazonaws.com/mongo-tracer/{MONGODB_TRACER_VERSION}/cs-mongo-tracer-installer.sh");
116-
let installer_path = env::temp_dir().join("cs-mongo-tracer-installer.sh");
117-
download_file(
118-
&Url::parse(installer_url.as_str()).unwrap(),
119-
&installer_path,
120-
)
121-
.await?;
122-
123-
let output = Command::new("bash")
124-
.arg(installer_path.to_str().unwrap())
125-
.stdout(Stdio::piped())
126-
.output()
127-
.map_err(|_| anyhow!("Failed to install mongo-tracer"))?;
128-
129-
if !output.status.success() {
130-
info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
131-
error!("stderr: {}", String::from_utf8_lossy(&output.stderr));
132-
bail!("Failed to install mongo-tracer");
133-
}
134-
135-
Ok(())
136-
}
137-
138-
pub async fn setup(system_info: &SystemInfo, config: &Config) -> Result<()> {
139-
install_valgrind(system_info).await?;
140-
141-
// TODO: move into setup of the Instruments struct
142-
if config.instruments.is_mongodb_enabled() {
143-
install_mongodb_tracer().await?;
144-
}
145-
146-
info!("Environment ready");
147-
Ok(())
148-
}
149-
150112
#[cfg(test)]
151113
mod tests {
152114
use insta::assert_snapshot;

0 commit comments

Comments
 (0)