performance-metrics: Refactor report file opening code

It should be closer to the use of the opened file.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-03-14 09:55:46 +00:00 committed by Sebastien Boeuf
parent d3be855b4b
commit 1004f870e1

View File

@ -464,17 +464,6 @@ 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 = Default::default();
@ -496,6 +485,17 @@ fn main() {
cleanup_tests();
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())
};
report_file
.write(
serde_json::to_string_pretty(&metrics_report)