summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-01-11 00:38:16 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-01-11 00:45:06 -0500
commit48331c92623aa3c3992a2dd827f9891bc00d276b (patch)
treef4080d6b4ee96250242c0ed9a6d0d93b49f98e0b
parent705e83096feda7976ed2fc1bb539e01b1eabd6a0 (diff)
Fix writing of test results
Update the TestResultsMap we read in and write that out, instead of writing out TestResultsVec; this avoids dropping results for commits we aren't considering. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--src/main.rs33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs
index 20b668d..2ddb26d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -48,8 +48,7 @@ fn results_read(fname: &str) -> Result<TestResultsMap, Box<dyn Error>> {
Ok(r)
}
-fn results_write(fname: &str, r: &TestResultsVec) -> Result<(), Box<dyn Error>> {
- let r = results_mapped(&r);
+fn results_write(fname: &str, r: &TestResultsMap) -> Result<(), Box<dyn Error>> {
let file_contents = toml::to_string(&r)?;
std::fs::write(fname, file_contents)?;
@@ -88,18 +87,6 @@ fn results_new(repo: &git2::Repository, range: &str) -> Result<TestResultsVec, g
Ok(data_points)
}
-fn results_mapped(r: &TestResultsVec) -> TestResultsMap {
- let mut mapped = HashMap::new();
-
- for i in r {
- if i.data_points.len() != 0 {
- mapped.insert(i.commit.clone(), i.data_points.clone());
- }
- }
-
- TestResultsMap { d: mapped }
-}
-
fn results_merge(r1: &mut TestResultsVec, r2: &TestResultsMap) {
for r1e in r1.iter_mut() {
let r2e = r2.d.get(&r1e.commit);
@@ -184,10 +171,8 @@ fn parse_test_output(output: &str) -> Option<f32> {
fn run_tests(repo: &git2::Repository, range: &str, test: &str) {
let mut results = results_new(&repo, range).unwrap();
- let existing = results_read(RESULTS);
- if let Ok(existing) = existing {
- results_merge(&mut results, &existing);
- }
+ let mut existing = results_read(RESULTS).unwrap_or(TestResultsMap { d: HashMap::new() });
+ results_merge(&mut results, &existing);
while let Some(idx) = pick_commit_to_test(&results, test) {
let output = Command::new("benchmark-git-commit.sh")
@@ -205,14 +190,22 @@ fn run_tests(repo: &git2::Repository, range: &str, test: &str) {
if let Some(result) = result {
results[idx].data_points.insert(test.to_string(), result);
- results_write(RESULTS, &results).unwrap();
+ let commit = results[idx].commit.to_string();
+
+ if existing.d.get(&commit).is_none() {
+ existing.d.insert(commit.clone(), HashMap::new());
+ }
+
+ existing.d.get_mut(&commit).unwrap().insert(test.to_string(), result);
+
+ results_write(RESULTS, &existing).unwrap();
} else {
eprintln!("Error parsing test output");
break;
}
}
- results_write(RESULTS, &results).unwrap();
+ results_write(RESULTS, &existing).unwrap();
}
fn log_with_results(repo: &git2::Repository,