mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
performance-metrics: Generate a summary report in Json
The report contains the test results with commit hash and date. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
@@ -31,6 +31,14 @@ pub struct PerformanceTestResult {
|
||||
min: f64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct MetricsReport {
|
||||
pub git_human_readable: String,
|
||||
pub git_revision: String,
|
||||
pub date: String,
|
||||
pub results: Vec<PerformanceTestResult>,
|
||||
}
|
||||
|
||||
pub struct PerformanceTestControl {
|
||||
test_time: u32,
|
||||
test_iterations: u32,
|
||||
@@ -307,8 +315,8 @@ lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
fn run_test_with_timetout(test: &'static PerformanceTest) -> Result<String, Error> {
|
||||
let (sender, receiver) = channel::<Result<String, Error>>();
|
||||
fn run_test_with_timetout(test: &'static PerformanceTest) -> Result<PerformanceTestResult, Error> {
|
||||
let (sender, receiver) = channel::<Result<PerformanceTestResult, Error>>();
|
||||
thread::spawn(move || {
|
||||
println!("Test '{}' running .. ({})", test.name, test.control);
|
||||
|
||||
@@ -318,7 +326,7 @@ fn run_test_with_timetout(test: &'static PerformanceTest) -> Result<String, Erro
|
||||
"Test '{}' .. ok: mean = {}, std_dev = {}",
|
||||
test_result.name, test_result.mean, test_result.std_dev
|
||||
);
|
||||
Ok(serde_json::to_string(&test_result).unwrap())
|
||||
Ok(test_result)
|
||||
}
|
||||
Err(_) => Err(Error::TestFailed),
|
||||
};
|
||||
@@ -339,18 +347,29 @@ fn run_test_with_timetout(test: &'static PerformanceTest) -> Result<String, Erro
|
||||
})?
|
||||
}
|
||||
|
||||
fn date() -> String {
|
||||
let output = test_infra::exec_host_command_output("date");
|
||||
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let test_filter = env::var("TEST_FILTER").map_or("".to_string(), |o| o);
|
||||
|
||||
// Run performance tests sequentially and report results (in both readable/json format)
|
||||
let mut metrics_report = MetricsReport {
|
||||
git_human_readable: env!("GIT_HUMAN_READABLE").to_string(),
|
||||
git_revision: env!("GIT_REVISION").to_string(),
|
||||
date: date(),
|
||||
results: Vec::new(),
|
||||
};
|
||||
|
||||
init_tests();
|
||||
|
||||
// Run performance tests sequentially and report results (in both readable/json format)
|
||||
let mut json_output = String::new();
|
||||
for test in TEST_LIST.iter() {
|
||||
if test.name.contains(&test_filter) {
|
||||
match run_test_with_timetout(test) {
|
||||
Ok(r) => {
|
||||
json_output.push_str(&r);
|
||||
metrics_report.results.push(r);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Aborting test due to error: '{:?}'", e);
|
||||
@@ -363,5 +382,8 @@ fn main() {
|
||||
cleanup_tests();
|
||||
|
||||
// Todo: Report/upload to the metrics database
|
||||
println!("\n\nTests result in json format: \n {}", json_output);
|
||||
println!(
|
||||
"\n\nTests result in json format: \n {}",
|
||||
serde_json::to_string_pretty(&metrics_report).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user