mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
performance-metrics: Add option "--report-file"
Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
458ae2c5be
commit
d650c684f1
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -638,6 +638,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"test_infra",
|
||||
"thiserror",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
|
@ -13,6 +13,7 @@ serde = { version = "1.0.136", features = ["rc"] }
|
||||
serde_derive = "1.0.136"
|
||||
serde_json = "1.0.78"
|
||||
test_infra = { path = "../test_infra" }
|
||||
thiserror = "1.0.30"
|
||||
wait-timeout = "0.2.0"
|
||||
|
||||
[build-dependencies]
|
||||
|
@ -18,11 +18,18 @@ use std::{
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
enum Error {
|
||||
#[error("Error: test timed-out")]
|
||||
TestTimeout,
|
||||
#[error("Error: test failed")]
|
||||
TestFailed,
|
||||
#[error("Error creating log file: {0}")]
|
||||
ReportFileCreation(std::io::Error),
|
||||
#[error("Error writing log file: {0}")]
|
||||
ReportFileWrite(std::io::Error),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
@ -377,6 +384,12 @@ fn main() {
|
||||
.takes_value(false)
|
||||
.required(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("report-file")
|
||||
.long("report-file")
|
||||
.help("Report file. Standard error is used if not specified")
|
||||
.takes_value(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if cmd_arguments.is_present("list-tests") {
|
||||
@ -393,6 +406,17 @@ fn main() {
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
let mut report_file: Box<dyn std::io::Write + Send> =
|
||||
if let Some(file) = cmd_arguments.value_of("report-file") {
|
||||
Box::new(
|
||||
std::fs::File::create(std::path::Path::new(file))
|
||||
.map_err(Error::ReportFileCreation)
|
||||
.unwrap(),
|
||||
)
|
||||
} else {
|
||||
Box::new(std::io::stderr())
|
||||
};
|
||||
|
||||
// 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(),
|
||||
@ -421,8 +445,12 @@ fn main() {
|
||||
cleanup_tests();
|
||||
|
||||
// Todo: Report/upload to the metrics database
|
||||
println!(
|
||||
"\n\nTests result in json format: \n {}",
|
||||
serde_json::to_string_pretty(&metrics_report).unwrap()
|
||||
);
|
||||
report_file
|
||||
.write(
|
||||
serde_json::to_string_pretty(&metrics_report)
|
||||
.unwrap()
|
||||
.as_bytes(),
|
||||
)
|
||||
.map_err(Error::ReportFileWrite)
|
||||
.unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user