performance-metrics: switch to argh

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2023-01-10 11:32:17 +00:00 committed by Rob Bradford
parent c6c081099f
commit 1ba995d952
3 changed files with 84 additions and 59 deletions

37
Cargo.lock generated
View File

@ -59,6 +59,35 @@ dependencies = [
"vmm-sys-util", "vmm-sys-util",
] ]
[[package]]
name = "argh"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c375edecfd2074d5edcc31396860b6e54b6f928714d0e097b983053fac0cabe3"
dependencies = [
"argh_derive",
"argh_shared",
]
[[package]]
name = "argh_derive"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa013479b80109a1bf01a039412b0f0013d716f36921226d86c6709032fb7a03"
dependencies = [
"argh_shared",
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "argh_shared"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "149f75bbec1827618262e0855a68f0f9a7f2edc13faebf33c4f16d6725edb6a9"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -370,6 +399,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.2.6" version = "0.2.6"
@ -758,7 +793,7 @@ dependencies = [
name = "performance-metrics" name = "performance-metrics"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "argh",
"dirs", "dirs",
"serde", "serde",
"serde_json", "serde_json",

View File

@ -6,7 +6,7 @@ edition = "2021"
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
clap = { version = "4.0.32", features = ["wrap_help"] } argh = "0.1.9"
dirs = "4.0.0" dirs = "4.0.0"
serde = { version = "1.0.151", features = ["rc", "derive"] } serde = { version = "1.0.151", features = ["rc", "derive"] }
serde_json = "1.0.89" serde_json = "1.0.89"

View File

@ -8,11 +8,11 @@ extern crate test_infra;
mod performance_tests; mod performance_tests;
use clap::{Arg, ArgAction, Command as ClapCommand}; use argh::FromArgs;
use performance_tests::*; use performance_tests::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
env, fmt, fmt,
process::Command, process::Command,
sync::{mpsc::channel, Arc}, sync::{mpsc::channel, Arc},
thread, thread,
@ -626,39 +626,37 @@ fn date() -> String {
String::from_utf8_lossy(&output.stdout).trim().to_string() String::from_utf8_lossy(&output.stdout).trim().to_string()
} }
#[derive(FromArgs)]
/// Generate the performance metrics data for Cloud Hypervisor
struct Options {
#[argh(switch, long = "list-tests")]
/// print the list of available metrics tests
list_tests: bool,
#[argh(option, long = "test-filter")]
/// filter metrics tests to run based on provided keywords
keywords: Vec<String>,
#[argh(option, long = "report-file")]
/// report file. Stderr is used if not specified
report_file: Option<String>,
#[argh(option, long = "iterations")]
/// override number of test iterations
iterations: Option<u32>,
#[argh(switch, short = 'V', long = "version")]
/// print version information
version: bool,
}
fn main() { fn main() {
let cmd_arguments = ClapCommand::new("performance-metrics") let opts: Options = argh::from_env();
.version(env!("GIT_HUMAN_READABLE"))
.author(env!("CARGO_PKG_AUTHORS")) if opts.version {
.about("Generate the performance metrics data for Cloud Hypervisor") println!("{} {}", env!("CARGO_BIN_NAME"), env!("GIT_HUMAN_READABLE"));
.arg( return;
Arg::new("test-filter") }
.long("test-filter")
.help("Filter metrics tests to run based on provided keywords")
.num_args(1)
.required(false),
)
.arg(
Arg::new("list-tests")
.long("list-tests")
.help("Print the list of availale metrics tests")
.num_args(0)
.action(ArgAction::SetTrue)
.required(false),
)
.arg(
Arg::new("report-file")
.long("report-file")
.help("Report file. Standard error is used if not specified")
.num_args(1),
)
.arg(
Arg::new("iterations")
.long("iterations")
.help("Override number of test iterations")
.num_args(1),
)
.get_matches();
// It seems that the tool (ethr) used for testing the virtio-net latency // It seems that the tool (ethr) used for testing the virtio-net latency
// is not stable on AArch64, and therefore the latency test is currently // is not stable on AArch64, and therefore the latency test is currently
@ -668,7 +666,7 @@ fn main() {
.filter(|t| !(cfg!(target_arch = "aarch64") && t.name == "virtio_net_latency_us")) .filter(|t| !(cfg!(target_arch = "aarch64") && t.name == "virtio_net_latency_us"))
.collect(); .collect();
if cmd_arguments.get_flag("list-tests") { if opts.list_tests {
for test in test_list.iter() { for test in test_list.iter() {
println!("\"{}\" ({})", test.name, test.control); println!("\"{}\" ({})", test.name, test.control);
} }
@ -676,10 +674,7 @@ fn main() {
return; return;
} }
let test_filter = match cmd_arguments.get_many::<String>("test-filter") { let test_filter = opts.keywords.iter().collect::<Vec<&String>>();
Some(s) => s.collect(),
None => Vec::new(),
};
// Run performance tests sequentially and report results (in both readable/json format) // Run performance tests sequentially and report results (in both readable/json format)
let mut metrics_report: MetricsReport = Default::default(); let mut metrics_report: MetricsReport = Default::default();
@ -687,11 +682,7 @@ fn main() {
init_tests(); init_tests();
let overrides = Arc::new(PerformanceTestOverrides { let overrides = Arc::new(PerformanceTestOverrides {
test_iterations: cmd_arguments test_iterations: opts.iterations,
.get_one::<String>("iterations")
.map(|s| s.parse())
.transpose()
.unwrap_or_default(),
}); });
for test in test_list.iter() { for test in test_list.iter() {
@ -710,19 +701,18 @@ fn main() {
cleanup_tests(); cleanup_tests();
let mut report_file: Box<dyn std::io::Write + Send> = let mut report_file: Box<dyn std::io::Write + Send> = if let Some(ref file) = opts.report_file {
if let Some(file) = cmd_arguments.get_one::<String>("report-file") { Box::new(
Box::new( std::fs::File::create(std::path::Path::new(file))
std::fs::File::create(std::path::Path::new(file)) .map_err(|e| {
.map_err(|e| { eprintln!("Error opening report file: {file}: {e}");
eprintln!("Error opening report file: {file}: {e}"); std::process::exit(1);
std::process::exit(1); })
}) .unwrap(),
.unwrap(), )
) } else {
} else { Box::new(std::io::stdout())
Box::new(std::io::stdout()) };
};
report_file report_file
.write_all( .write_all(