diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-05 19:53:00 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-05 19:53:00 +0200 |
commit | 83eebad6645944ecca6f292c9e2677c1a30f23af (patch) | |
tree | 096d97118ae30c955b3f40260e0fd456b33e35ff | |
parent | f57152e112a55c1b821469cb911e2e16890585c6 (diff) | |
download | obnam-benchmark-83eebad6645944ecca6f292c9e2677c1a30f23af.tar.gz |
refactor: move backup, restore to separate functions, for clarity
Sponsored-by: author
-rw-r--r-- | src/step.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/step.rs b/src/step.rs index 1142765..ae9a32c 100644 --- a/src/step.rs +++ b/src/step.rs @@ -52,7 +52,7 @@ impl Step { pub fn execute(&self, current: &mut Option<String>) -> Result<Option<OpMeasurements>, StepError> { let now = Instant::now(); - let op = match self { + let om = match self { Self::Start(name) => { *current = Some(name.to_string()); println!("start benchmark {}", name); @@ -77,27 +77,34 @@ impl Step { } Self::Backup(x) => { println!("backup {}", x); - Some(Operation::Backup) + Some(backup(current.as_ref().unwrap())?) } Self::Restore(x) => { println!("restore {}", x); - Some(Operation::Restore) + Some(restore(current.as_ref().unwrap())?) } }; let t = std::time::Duration::from_millis(10); std::thread::sleep(t); - let m = if let Some(op) = op { + if let Some(mut om) = om { let ms = now.elapsed().as_millis(); - assert!(current.is_some()); - let current = current.as_ref().unwrap(); - let mut om = OpMeasurements::new(current, op); om.push(Measurement::DurationMs(ms)); - Some(om) + Ok(Some(om)) } else { - None - }; - Ok(m) + Ok(None) + } } } + +fn backup(current: &str) -> Result<OpMeasurements, StepError> { + let mut om = OpMeasurements::new(current, Operation::Backup); + om.push(Measurement::TotalFiles(0)); + om.push(Measurement::TotalData(0)); + Ok(om) +} + +fn restore(current: &str) -> Result<OpMeasurements, StepError> { + Ok(OpMeasurements::new(current, Operation::Restore)) +} |