Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File output for benchmark results. #42

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ divan-macros = { version = "=0.1.14", path = "macros" }
cfg-if = "1"
clap = { version = "4", default-features = false, features = ["std", "env"] }
condtype = "1.3"
regex = { package = "regex-lite", version = "0.1", default-features = false, features = ["std", "string"] }
regex = { package = "regex-lite", version = "0.1", default-features = false, features = [
"std",
"string",
] }

serde_json = "1.0"

[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
Expand Down
33 changes: 32 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::path::PathBuf;

use clap::{builder::PossibleValue, value_parser, Arg, ArgAction, ColorChoice, Command, ValueEnum};

use crate::{
config::{ParsedSeconds, SortingAttr},
config::{FileFormat, ParsedSeconds, SortingAttr},
counter::MaxCountUInt,
time::TimerKind,
};
Expand Down Expand Up @@ -156,6 +158,21 @@ pub(crate) fn command() -> Command {
.help("Set every benchmark to have a throughput of N string scalars")
.value_parser(value_parser!(MaxCountUInt)),
)
.arg(
option("file")
OliverKillane marked this conversation as resolved.
Show resolved Hide resolved
.env("DIVAN_WRITE_FILE")
.value_name("PATH")
.help("Set the file path to append the results to")
.value_parser(value_parser!(PathBuf))
)
.arg(
option("format")
.env("DIVAN_FILE_FORMAT")
.requires("file")
.value_name("FORMAT")
.help("Set output file type")
.value_parser(value_parser!(FileFormat))
)
// ignored:
.args([ignored_flag("bench"), ignored_flag("nocapture"), ignored_flag("show-output")])
}
Expand Down Expand Up @@ -188,3 +205,17 @@ impl ValueEnum for SortingAttr {
Some(PossibleValue::new(name))
}
}

impl ValueEnum for FileFormat {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Json, Self::JsonFlat]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
let name = match self {
FileFormat::Json => "json",
FileFormat::JsonFlat => "jsonflat",
};
Some(PossibleValue::new(name))
}
}
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,10 @@ impl SortingAttr {
Ordering::Equal
}
}

#[derive(Clone, Copy, Default)]
pub(crate) enum FileFormat {
#[default]
Json,
JsonFlat,
}
Loading