feat(runner): add TOML matrix benchmark config support

This commit is contained in:
2026-02-11 15:19:45 +02:00
parent 1c6625a04c
commit cf8c1d9f84
3 changed files with 18 additions and 13 deletions

2
.gitignore vendored
View File

@@ -17,3 +17,5 @@ target/
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
benchmarks.toml

View File

@@ -11,8 +11,8 @@ pub struct Args {
pub mode: KeyExchangeMode,
/// Server address to connect to.
#[arg(long)]
pub server: SocketAddr,
#[arg(long, required_unless_present = "config")]
pub server: Option<SocketAddr>,
/// Payload size in bytes to request from server.
#[arg(long, default_value = "1024")]

View File

@@ -1,4 +1,6 @@
use miette::{Context, IntoDiagnostic};
use crate::args::Args;
use common::KeyExchangeMode;
use miette::{Context, IntoDiagnostic, miette};
use serde::Deserialize;
use std::{fs::read_to_string, net::SocketAddr, path::PathBuf};
@@ -25,7 +27,9 @@ pub fn load_from_file(path: &PathBuf) -> miette::Result<Config> {
let content = read_to_string(path)
.into_diagnostic()
.context(format!("failed to read config file: {}", path.display()))?;
let config: Config = toml::from_str(&content).into_diagnostic().context(format!(
let config = toml::from_str::<Config>(&content)
.into_diagnostic()
.context(format!(
"failed to parse TOML config from file {}",
path.display()
))?;
@@ -36,16 +40,17 @@ pub fn load_from_file(path: &PathBuf) -> miette::Result<Config> {
///
/// # Errors
/// Never returns an error, but returns Result for consistency.
pub fn load_from_cli(args: &crate::args::Args) -> miette::Result<Config> {
let mode = args.mode.to_string();
pub fn load_from_cli(args: &Args) -> miette::Result<Config> {
Ok(Config {
benchmarks: vec![BenchmarkConfig {
mode,
mode: args.mode.to_string(),
payload: args.payload_bytes,
iters: args.iters,
warmup: args.warmup,
concurrency: args.concurrency,
server: args.server,
server: args
.server
.ok_or_else(|| miette!("--server is required when not using --config"))?,
}],
})
}
@@ -60,5 +65,3 @@ impl Config {
.unwrap_or(KeyExchangeMode::X25519)
}
}
use common::KeyExchangeMode;