summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-05 15:24:58 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-05 15:24:58 +0200
commit55000324bb4d6434fa147ce4c835a2c8cc76b757 (patch)
tree2a1be73ae027ef2304774e6988e54c80f69b905d /src
parentf750b4b68f4c86f1344ea6f5b34e9767c1e2f7b6 (diff)
downloadobnam-benchmark-55000324bb4d6434fa147ce4c835a2c8cc76b757.tar.gz
feat: add placeholders for what needs to happen
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/obnam-benchmark.rs34
-rw-r--r--src/lib.rs72
2 files changed, 99 insertions, 7 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs
index bc9c7de..8b31a82 100644
--- a/src/bin/obnam-benchmark.rs
+++ b/src/bin/obnam-benchmark.rs
@@ -15,6 +15,7 @@ fn real_main() -> anyhow::Result<()> {
let opt = Opt::from_args();
match opt.cmd {
+ Command::Run(x) => x.run()?,
Command::Spec(x) => x.run()?,
}
@@ -29,10 +30,43 @@ struct Opt {
#[derive(Debug, StructOpt)]
enum Command {
+ Run(Run),
Spec(Spec),
}
#[derive(Debug, StructOpt)]
+struct Run {
+ #[structopt(parse(from_os_str))]
+ spec: PathBuf,
+}
+
+impl Run {
+ fn run(&self) -> anyhow::Result<()> {
+ let spec = Specification::from_file(&self.spec)?;
+
+ for benchmark in spec.benchmarks() {
+ println!("benchmark {}", benchmark.name());
+ println!("start obnam server with empty chunks dir");
+ println!("create empty test data directory");
+ for backup in benchmark.backups() {
+ println!("make changes to test data");
+ for change in backup.changes() {
+ change.execute()?;
+ }
+ println!("run backup, measure time and chunks directory");
+ }
+ for _ in benchmark.backups() {
+ println!("run restore, measure time")
+ }
+ println!("stop obnam server");
+ println!("clean up test data directory");
+ }
+
+ Ok(())
+ }
+}
+
+#[derive(Debug, StructOpt)]
struct Spec {
#[structopt(parse(from_os_str))]
spec: PathBuf,
diff --git a/src/lib.rs b/src/lib.rs
index 7f3c5e4..1122ada 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,35 +1,93 @@
use serde::{Deserialize, Serialize};
+use std::fs::File;
+use std::path::{Path, PathBuf};
#[derive(Debug, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
pub struct Specification {
benchmarks: Vec<Benchmark>,
}
+#[derive(Debug, thiserror::Error)]
+pub enum SpecificationError {
+ #[error("Couldn't open {0}: {1}")]
+ Open(PathBuf, std::io::Error),
+
+ #[error("Couldn't read YAML specification from {0}:\n {1}")]
+ Yaml(PathBuf, serde_yaml::Error),
+}
+
#[derive(Debug, Serialize, Deserialize)]
-struct Benchmark {
+pub struct Benchmark {
benchmark: String,
backups: Vec<Backup>,
}
#[derive(Debug, Serialize, Deserialize)]
-struct Backup {
- changes: Vec<Change>,
+pub struct Backup {
+ pub changes: Vec<Change>,
}
#[derive(Debug, Serialize, Deserialize)]
-enum Change {
- Create(CreateFiles),
+pub enum Change {
+ #[serde(rename = "create")]
+ Create(Create),
+
+ #[serde(rename = "delete")]
Delete(FileCount),
+
+ #[serde(rename = "rename")]
Rename(FileCount),
}
#[derive(Debug, Serialize, Deserialize)]
-struct CreateFiles {
+pub struct Create {
files: u64,
file_size: u64,
}
#[derive(Debug, Serialize, Deserialize)]
-struct FileCount {
+pub struct FileCount {
files: u64,
}
+
+impl Specification {
+ pub fn from_file(filename: &Path) -> Result<Self, SpecificationError> {
+ let f = File::open(filename)
+ .map_err(|err| SpecificationError::Open(filename.to_path_buf(), err))?;
+ let spec = serde_yaml::from_reader(f)
+ .map_err(|err| SpecificationError::Yaml(filename.to_path_buf(), err))?;
+ Ok(spec)
+ }
+
+ pub fn benchmarks(&self) -> impl Iterator<Item = &Benchmark> {
+ self.benchmarks.iter()
+ }
+}
+
+impl Benchmark {
+ pub fn name(&self) -> &str {
+ &self.benchmark
+ }
+
+ pub fn backups(&self) -> impl Iterator<Item = &Backup> {
+ self.backups.iter()
+ }
+}
+
+impl Backup {
+ pub fn changes(&self) -> impl Iterator<Item = &Change> {
+ self.changes.iter()
+ }
+}
+
+impl Change {
+ pub fn execute(&self) -> Result<(), SpecificationError> {
+ match self {
+ Change::Create(x) => println!("create {} {}", x.files, x.file_size),
+ Change::Rename(x) => println!("rename {}", x.files),
+ Change::Delete(x) => println!("delete {}", x.files),
+ }
+ Ok(())
+ }
+}