Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix benchmark writer #9626

Merged
2 commits merged into from
Aug 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions utils/frame/benchmarking-cli/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn io_error(s: &str) -> std::io::Error {
}

// This function takes a list of `BenchmarkBatch` and organizes them by pallet into a `HashMap`.
// So this: `[(p1, b1), (p1, b2), (p1, b3), (p2, b1), (p2, b2)]`
// So this: `[(p1, b1), (p1, b2), (p2, b1), (p1, b3), (p2, b2)]`
// Becomes:
//
// ```
Expand All @@ -124,11 +124,9 @@ fn map_results(
return Err(io_error("empty batches"))
}

let mut all_benchmarks = HashMap::new();
let mut pallet_benchmarks = Vec::new();
let mut all_benchmarks = HashMap::<_, Vec<BenchmarkData>>::new();

let mut batches_iter = batches.iter().peekable();
while let Some(batch) = batches_iter.next() {
for batch in batches {
// Skip if there are no results
if batch.time_results.is_empty() {
continue
Expand All @@ -137,21 +135,8 @@ fn map_results(
let pallet_string = String::from_utf8(batch.pallet.clone()).unwrap();
let instance_string = String::from_utf8(batch.instance.clone()).unwrap();
let benchmark_data = get_benchmark_data(batch, storage_info, analysis_choice);
let pallet_benchmarks = all_benchmarks.entry((pallet_string, instance_string)).or_default();
pallet_benchmarks.push(benchmark_data);

// Check if this is the end of the iterator
if let Some(next) = batches_iter.peek() {
// Next pallet is different than current pallet, save and create new data.
let next_pallet = String::from_utf8(next.pallet.clone()).unwrap();
let next_instance = String::from_utf8(next.instance.clone()).unwrap();
if next_pallet != pallet_string || next_instance != instance_string {
all_benchmarks.insert((pallet_string, instance_string), pallet_benchmarks.clone());
pallet_benchmarks = Vec::new();
}
} else {
// This is the end of the iterator, so push the final data.
all_benchmarks.insert((pallet_string, instance_string), pallet_benchmarks.clone());
}
}
Ok(all_benchmarks)
}
Expand Down