Change the structure of everything to remove Manager trait.

Manager is now a simple struct, that no longer stores the results,
but instead takes in a Vec<ExportEntry> and has all exporters
write from this collection.

Benchmark and run both return their results, no more mut manager.

Change f64 in ExportEntry to hyperfine::internal::Second.

Remove multiple export files for a single type.
This commit is contained in:
Steve Pentland authored and David Peter committed 2018-03-19 07:53:10 +01:00
1 parent c4688a7386
commit 7c7277777a
3 files changed
+40 -61

No files matched your search

+14 -30
View File
@@ -4,6 +4,8 @@ use self::csv::CsvExporter;
use std::io::Result;
use hyperfine::internal::Second;
/// The ExportEntry is the main set of values that will
/// be exported to files when requested.
#[derive(Debug, Default, Clone, Serialize)]
@@ -11,13 +13,13 @@ pub struct ExportEntry {
/// The command that was run
command: String,
/// The mean run time
mean: f64,
mean: Second,
/// The standard deviation of all run times
stddev: f64,
stddev: Second,
/// Time spend in user space
user: f64,
user: Second,
/// Time spent in system space
system: f64,
system: Second,
}
impl ExportEntry {
@@ -47,47 +49,29 @@ trait ResultExporter {
fn write(&self, values: &Vec<ExportEntry>) -> Result<()>;
}
/// The ExportManager handles coordination of multiple ResultExporters
pub trait ExportManager {
/// Add a new exporter to this manager for the given type
fn add_exporter(&mut self, for_type: &ResultExportType);
/// Add a new result to all exporters contained in the manager
fn add_result(&mut self, result: ExportEntry);
/// Trigger writes from all exporters
fn write_results(&self) -> Result<()>;
}
/// Create a new ExportManager
pub fn create_export_manager() -> Box<ExportManager> {
Box::new(Exporter {
pub fn create_export_manager() -> ExportManager {
ExportManager {
exporters: Vec::new(),
results: Vec::new(),
})
}
}
/// The Exporter is the internal implementation of the ExportManager
struct Exporter {
pub struct ExportManager {
exporters: Vec<Box<ResultExporter>>,
results: Vec<ExportEntry>,
}
impl ExportManager for Exporter {
fn add_exporter(&mut self, for_type: &ResultExportType) {
impl ExportManager {
pub fn add_exporter(&mut self, for_type: &ResultExportType) {
match for_type {
&ResultExportType::Csv(ref file_name) => self.exporters
.push(Box::from(CsvExporter::new(file_name.clone()))),
};
}
fn add_result(&mut self, result: ExportEntry) {
self.results.push(result);
}
fn write_results(&self) -> Result<()> {
pub fn write_results(&self, to_write: Vec<ExportEntry>) -> Result<()> {
for exp in &self.exporters {
exp.write(&self.results)?;
exp.write(&to_write)?;
}
Ok(())
}