use std::{env, fs, process};
use euv_performance::{
BENCH_FLAG_FILTER, BENCH_FLAG_JSON, BENCH_FLAG_OBSERVABILITY_JSON, BENCH_FLAG_STRESS_MATRIX,
BENCH_FLAG_TTFF, BenchReport, ColdStartTtffReport, OBSERVABILITY_DEFAULT_COMMIT,
OBSERVABILITY_DEFAULT_PROFILE, ObservabilityReportV1, StressMatrixReport,
cold_start_ttff_to_json, emit_stress_observability_report, format_bench_report,
format_cold_start_ttff_report, format_stress_matrix_report, observability_report_to_json,
report_to_json, run_cold_start_ttff_report, run_filtered_benchmark_suite,
run_filtered_stress_matrix, stress_matrix_to_json,
};
fn main() {
let args: Vec<String> = env::args().collect();
let mut filter: Option<String> = None;
let mut stress_matrix: bool = false;
let mut emit_json: bool = false;
let mut emit_ttff: bool = false;
let mut emit_observability: bool = false;
let mut observability_out_path: Option<String> = None;
let mut idx: usize = 1;
while idx < args.len() {
let arg: &str = args[idx].as_str();
if arg == BENCH_FLAG_FILTER {
if let Some(next_val) = args.get(idx + 1) {
filter = Some(next_val.clone());
idx += 1;
}
} else if let Some(rest) = arg.strip_prefix(BENCH_FLAG_FILTER)
&& let Some(val) = rest.strip_prefix('=')
&& !val.is_empty()
{
filter = Some(val.to_string());
} else if arg == BENCH_FLAG_STRESS_MATRIX {
stress_matrix = true;
} else if arg == BENCH_FLAG_JSON {
emit_json = true;
} else if arg == BENCH_FLAG_TTFF {
emit_ttff = true;
} else if arg == BENCH_FLAG_OBSERVABILITY_JSON {
emit_observability = true;
if let Some(next_val) = args.get(idx + 1)
&& !next_val.starts_with('-')
{
observability_out_path = Some(next_val.clone());
idx += 1;
}
} else if let Some(rest) = arg.strip_prefix(BENCH_FLAG_OBSERVABILITY_JSON)
&& let Some(val) = rest.strip_prefix('=')
&& !val.is_empty()
{
emit_observability = true;
observability_out_path = Some(val.to_string());
}
idx += 1;
}
if emit_observability {
let report: StressMatrixReport = run_filtered_stress_matrix(filter.as_deref());
let obs: ObservabilityReportV1 = emit_stress_observability_report(
&report,
OBSERVABILITY_DEFAULT_COMMIT,
OBSERVABILITY_DEFAULT_PROFILE,
);
let payload: String = observability_report_to_json(&obs);
if let Some(out_path) = observability_out_path {
if let Err(err) = fs::write(&out_path, format!("{payload}\n")) {
eprintln!("Failed to write observability JSON to {out_path}: {err}");
process::exit(1);
}
} else {
println!("{payload}");
}
} else if emit_ttff {
let report: ColdStartTtffReport = run_cold_start_ttff_report(8);
if emit_json {
println!("{}", cold_start_ttff_to_json(&report));
} else {
print!("{}", format_cold_start_ttff_report(&report));
}
} else if stress_matrix {
let report: StressMatrixReport = run_filtered_stress_matrix(filter.as_deref());
if emit_json {
println!("{}", stress_matrix_to_json(&report));
} else {
print!("{}", format_stress_matrix_report(&report));
}
} else {
let report: BenchReport = run_filtered_benchmark_suite(filter.as_deref());
if emit_json {
println!("{}", report_to_json(&report));
} else {
print!("{}", format_bench_report(&report));
}
}
}