Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use crate::executor::ExecutorName;
use crate::prelude::*;
use crate::run_environment::RepositoryProvider;
use crate::{app::Cli, config::CodSpeedConfig};
use crate::{cli::Cli, config::CodSpeedConfig};
use console::style;
use gql_client::{Client as GQLClient, ClientConfig};
use nestify::nest;
Expand Down
2 changes: 1 addition & 1 deletion src/binary_installer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli::run::helpers::download_file;
use crate::prelude::*;
use crate::run::helpers::download_file;
use semver::Version;
use std::process::Command;
use tempfile::NamedTempFile;
Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions src/exec/mod.rs → src/cli/exec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::ExecAndRunSharedArgs;
use crate::api_client::CodSpeedAPIClient;
use crate::binary_installer::ensure_binary_installed;
use crate::config::CodSpeedConfig;
use crate::executor;
use crate::prelude::*;
use crate::project_config::ProjectConfig;
use crate::project_config::merger::ConfigMerger;
use crate::run::uploader::UploadResult;
use crate::upload::UploadResult;
use clap::Args;
use std::path::Path;

Expand Down Expand Up @@ -36,7 +37,7 @@ pub fn wrap_with_exec_harness(
#[derive(Args, Debug)]
pub struct ExecArgs {
#[command(flatten)]
pub shared: crate::run::ExecAndRunSharedArgs,
pub shared: ExecAndRunSharedArgs,

#[command(flatten)]
pub walltime_args: exec_harness::walltime::WalltimeExecutionArgs,
Expand Down Expand Up @@ -96,6 +97,11 @@ pub async fn execute_with_harness(
setup_cache_dir: Option<&Path>,
) -> Result<()> {
let mut execution_context = executor::ExecutionContext::try_from((config, codspeed_config))?;

if execution_context.is_local() {
super::show_banner();
}

debug!("config: {:#?}", execution_context.config);
let executor = executor::get_executor_from_mode(
&execution_context.config.mode,
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions src/cli/exec/poll_results.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use console::style;

use crate::api_client::CodSpeedAPIClient;
use crate::cli::run::helpers::benchmark_display::{build_benchmark_table, build_detailed_summary};
use crate::prelude::*;
use crate::upload::{UploadResult, poll_run_report};

#[allow(clippy::borrowed_box)]
pub async fn poll_results(
api_client: &CodSpeedAPIClient,
upload_result: &UploadResult,
) -> Result<()> {
let response = poll_run_report(api_client, upload_result).await?;

if !response.run.results.is_empty() {
end_group!();
start_group!("Benchmark results");

if response.run.results.len() == 1 {
let summary = build_detailed_summary(&response.run.results[0]);
info!("\n{summary}");
} else {
let table = build_benchmark_table(&response.run.results);
info!("\n{table}");
}

info!(
"\nTo see the full report, visit: {}",
style(response.run.url).blue().bold().underlined()
);
}

Ok(())
}
15 changes: 12 additions & 3 deletions src/app.rs → src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
mod auth;
pub(crate) mod exec;
pub(crate) mod run;
mod setup;
mod shared;
mod use_mode;

pub(crate) use shared::*;

use std::path::PathBuf;

use crate::{
api_client::CodSpeedAPIClient,
auth,
config::CodSpeedConfig,
exec,
local_logger::{CODSPEED_U8_COLOR_CODE, init_local_logger},
prelude::*,
project_config::ProjectConfig,
run, setup,
};
use clap::{
Parser, Subcommand,
Expand Down Expand Up @@ -78,6 +84,8 @@ enum Commands {
Auth(auth::AuthArgs),
/// Pre-install the codspeed executors
Setup,
/// Set the codspeed mode for the rest of the shell session
Use(use_mode::UseArgs),
}

pub async fn run() -> Result<()> {
Expand Down Expand Up @@ -127,6 +135,7 @@ pub async fn run() -> Result<()> {
}
Commands::Auth(args) => auth::run(args, &api_client, cli.config_name.as_deref()).await?,
Commands::Setup => setup::setup(setup_cache_dir).await?,
Commands::Use(args) => use_mode::run(args)?,
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::api_client::FetchLocalRunBenchmarkResult;
use crate::cli::run::helpers;
use crate::executor::ExecutorName;
use crate::run::helpers;
use std::collections::HashMap;
use std::time::Duration;
use tabled::settings::object::{Columns, Rows};
use tabled::settings::panel::Panel;
use tabled::settings::style::HorizontalLine;
use tabled::settings::{Alignment, Color, Modify, Style};
use tabled::{Table, Tabled};

pub const RUN_PROCESSING_MAX_DURATION: Duration = Duration::from_secs(60 * 5); // 5 minutes
pub const POLLING_INTERVAL: Duration = Duration::from_secs(1);

fn format_with_thousands_sep(n: u64) -> String {
let s = n.to_string();
let mut result = String::new();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Git LFS file not shown
File renamed without changes.
136 changes: 10 additions & 126 deletions src/run/mod.rs → src/cli/run/mod.rs
Original file line number Diff line number Diff line change
@@ -1,138 +1,19 @@
use crate::VERSION;
use super::ExecAndRunSharedArgs;
use crate::api_client::CodSpeedAPIClient;
use crate::config::CodSpeedConfig;
use crate::executor;
use crate::executor::Config;
use crate::prelude::*;
use crate::project_config::ProjectConfig;
use crate::project_config::merger::ConfigMerger;
use crate::run::uploader::UploadResult;
use crate::run_environment::interfaces::RepositoryProvider;
use crate::runner_mode::RunnerMode;
use crate::upload::UploadResult;
use clap::{Args, ValueEnum};
use std::path::Path;
use std::path::PathBuf;

pub mod check_system;
pub mod helpers;
pub(crate) mod poll_results;
pub mod run_index_state;
pub(crate) mod uploader;

pub mod logger;

pub(crate) fn show_banner() {
let banner = format!(
r#"
______ __ _____ __
/ ____/____ ____/ // ___/ ____ ___ ___ ____/ /
/ / / __ \ / __ / \__ \ / __ \ / _ \ / _ \ / __ /
/ /___ / /_/ // /_/ / ___/ // /_/ // __// __// /_/ /
\____/ \____/ \__,_/ /____// .___/ \___/ \___/ \__,_/
https://codspeed.io /_/ runner v{VERSION}
"#
);
println!("{banner}");
debug!("codspeed v{VERSION}");
}

#[derive(Debug, Copy, Clone, PartialEq, ValueEnum, Default)]
pub enum UnwindingMode {
/// Use the frame pointer for unwinding. Requires the binary to be compiled with frame pointers enabled.
#[clap(name = "fp")]
FramePointer,

/// Use DWARF unwinding. This does not require any special compilation flags and is enabled by default.
#[default]
Dwarf,
}

#[derive(Args, Debug, Clone)]
pub struct PerfRunArgs {
/// Enable the linux perf profiler to collect granular performance data.
/// This is only supported on Linux.
#[arg(long, env = "CODSPEED_PERF_ENABLED", default_value_t = true)]
pub enable_perf: bool,

/// The unwinding mode that should be used with perf to collect the call stack.
#[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")]
pub perf_unwinding_mode: Option<UnwindingMode>,
}

/// Arguments shared between run and exec commands
#[derive(Args, Debug, Clone)]
pub struct ExecAndRunSharedArgs {
/// The upload URL to use for uploading the results, useful for on-premises installations
#[arg(long, env = "CODSPEED_UPLOAD_URL")]
pub upload_url: Option<String>,

/// The token to use for uploading the results,
///
/// It can be either a CodSpeed token retrieved from the repository setting
/// or an OIDC token issued by the identity provider.
#[arg(long, env = "CODSPEED_TOKEN")]
pub token: Option<String>,

/// The repository the benchmark is associated with, under the format `owner/repo`.
#[arg(short, long, env = "CODSPEED_REPOSITORY")]
pub repository: Option<String>,

/// The repository provider to use in case --repository is used. Defaults to github
#[arg(
long,
env = "CODSPEED_PROVIDER",
requires = "repository",
ignore_case = true
)]
pub provider: Option<RepositoryProvider>,

/// The directory where the command will be executed.
#[arg(long)]
pub working_directory: Option<String>,

/// The mode to run the benchmarks in.
#[arg(short, long, value_enum, env = "CODSPEED_RUNNER_MODE")]
pub mode: RunnerMode,

/// Profile folder to use for the run.
#[arg(long)]
pub profile_folder: Option<PathBuf>,

/// Only for debugging purposes, skips the upload of the results
#[arg(
long,
default_value = "false",
hide = true,
env = "CODSPEED_SKIP_UPLOAD"
)]
pub skip_upload: bool,

/// Used internally to upload the results after running the benchmarks in a sandbox environment
/// with no internet access
#[arg(long, default_value = "false", hide = true)]
pub skip_run: bool,

/// Only for debugging purposes, skips the setup of the runner
#[arg(long, default_value = "false", hide = true)]
pub skip_setup: bool,

/// Allow runs without any benchmarks to succeed instead of failing
#[arg(long, default_value = "false", hide = true)]
pub allow_empty: bool,

/// The version of the go-runner to use (e.g., 1.2.3, 1.0.0-beta.1)
/// If not specified, the latest version will be installed
#[arg(long, env = "CODSPEED_GO_RUNNER_VERSION", value_parser = parse_version)]
pub go_runner_version: Option<semver::Version>,

#[command(flatten)]
pub perf_run_args: PerfRunArgs,
}

/// Parser for go-runner version that validates semver format
fn parse_version(s: &str) -> Result<semver::Version, String> {
semver::Version::parse(s).map_err(|e| format!("Invalid semantic version: {e}"))
}
mod poll_results;

#[derive(Args, Debug)]
pub struct RunArgs {
Expand Down Expand Up @@ -179,14 +60,17 @@ pub enum MessageFormat {
impl RunArgs {
/// Constructs a new `RunArgs` with default values for testing purposes
pub fn test() -> Self {
use super::PerfRunArgs;
use crate::RunnerMode;

Self {
shared: ExecAndRunSharedArgs {
upload_url: None,
token: None,
repository: None,
provider: None,
working_directory: None,
mode: RunnerMode::Simulation,
mode: Some(RunnerMode::Simulation),
profile_folder: None,
skip_upload: false,
skip_run: false,
Expand Down Expand Up @@ -263,7 +147,7 @@ pub async fn run(
executor::ExecutionContext::try_from((config, codspeed_config))?;

if !execution_context.is_local() {
show_banner();
super::show_banner();
}
debug!("config: {:#?}", execution_context.config);

Expand Down Expand Up @@ -292,10 +176,10 @@ pub async fn run(
default_walltime,
} => {
args.command =
crate::exec::multi_targets::build_pipe_command(targets, default_walltime)?;
super::exec::multi_targets::build_pipe_command(targets, default_walltime)?;
let config = Config::try_from(args)?;

crate::exec::execute_with_harness(config, api_client, codspeed_config, setup_cache_dir)
super::exec::execute_with_harness(config, api_client, codspeed_config, setup_cache_dir)
.await?;
}
}
Expand Down
Loading
Loading