From 29e243ac81dee651e31ad7edc76db863f9e9c64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 1 Jan 2024 15:44:39 +0100 Subject: [PATCH] bencher: move html gen into own module --- crates/bencher/src/html.rs | 80 +++++++++++++++++++++++++++++ crates/bencher/src/main.rs | 1 + crates/bencher/src/set.rs | 100 +++++-------------------------------- 3 files changed, 93 insertions(+), 88 deletions(-) create mode 100644 crates/bencher/src/html.rs diff --git a/crates/bencher/src/html.rs b/crates/bencher/src/html.rs new file mode 100644 index 0000000..e848741 --- /dev/null +++ b/crates/bencher/src/html.rs @@ -0,0 +1,80 @@ +use indexmap::{IndexMap, IndexSet}; +use itertools::Itertools; + +use crate::set::TrackerCoreCountResults; + +pub fn html_best_results(results: &[TrackerCoreCountResults]) -> String { + let mut all_implementation_names = IndexSet::new(); + + for core_count_results in results { + all_implementation_names.extend( + core_count_results + .implementations + .iter() + .map(|r| r.name.clone()), + ); + } + + let mut data_rows = Vec::new(); + + for core_count_results in results { + let best_results = core_count_results + .implementations + .iter() + .map(|implementation| (implementation.name.clone(), implementation.best_result())) + .collect::>(); + + let best_results_for_all_implementations = all_implementation_names + .iter() + .map(|name| best_results.get(name).cloned().flatten()) + .collect::>(); + + let data_row = format!( + " + + {} + {} + + ", + core_count_results.core_count, + best_results_for_all_implementations + .into_iter() + .map(|result| { + if let Some(r) = result { + format!( + r#"{}"#, + r.tracker_info, + r.tracker_process_stats.avg_cpu_utilization, + r.average_responses, + ) + } else { + "-".to_string() + } + }) + .join("\n"), + ); + + data_rows.push(data_row); + } + + format!( + " + + + + + {} + + + + {} + +
CPU cores
+ ", + all_implementation_names + .iter() + .map(|name| format!("{name}")) + .join("\n"), + data_rows.join("\n") + ) +} diff --git a/crates/bencher/src/main.rs b/crates/bencher/src/main.rs index 2ed2be8..5494d5c 100644 --- a/crates/bencher/src/main.rs +++ b/crates/bencher/src/main.rs @@ -1,4 +1,5 @@ pub mod common; +pub mod html; pub mod protocols; pub mod run; pub mod set; diff --git a/crates/bencher/src/set.rs b/crates/bencher/src/set.rs index 597b8fa..837aae2 100644 --- a/crates/bencher/src/set.rs +++ b/crates/bencher/src/set.rs @@ -1,10 +1,10 @@ use std::rc::Rc; -use indexmap::{IndexMap, IndexSet}; -use itertools::Itertools; +use indexmap::IndexMap; use crate::{ common::{CpuDirection, CpuMode, TaskSetCpuList}, + html::html_best_results, run::{ProcessRunner, ProcessStats, RunConfig}, }; @@ -106,21 +106,21 @@ pub fn run_sets( }) .collect::>(); - html_summary(&results); + html_best_results(&results); } pub struct TrackerCoreCountResults { - core_count: usize, - implementations: Vec, + pub core_count: usize, + pub implementations: Vec, } pub struct ImplementationResults { - name: String, - configurations: Vec, + pub name: String, + pub configurations: Vec, } impl ImplementationResults { - fn best_result(&self) -> Option { + pub fn best_result(&self) -> Option { self.configurations .iter() .filter_map(|c| c.best_result()) @@ -135,7 +135,7 @@ impl ImplementationResults { } pub struct TrackerConfigurationResults { - load_tests: Vec, + pub load_tests: Vec, } impl TrackerConfigurationResults { @@ -227,89 +227,13 @@ impl LoadTestRunResults { #[derive(Clone)] pub struct LoadTestRunResultsSuccess { - average_responses: f32, + pub average_responses: f32, // tracker_keys: IndexMap, - tracker_info: String, - tracker_process_stats: ProcessStats, + pub tracker_info: String, + pub tracker_process_stats: ProcessStats, // load_test_keys: IndexMap, } pub struct LoadTestRunResultsFailure { // load_test_keys: IndexMap, } - -pub fn html_summary(results: &[TrackerCoreCountResults]) { - let mut all_implementation_names = IndexSet::new(); - - for core_count_results in results { - all_implementation_names.extend( - core_count_results - .implementations - .iter() - .map(|r| r.name.clone()), - ); - } - - let mut data_rows = Vec::new(); - - for core_count_results in results { - let best_results = core_count_results - .implementations - .iter() - .map(|implementation| (implementation.name.clone(), implementation.best_result())) - .collect::>(); - - let best_results_for_all_implementations = all_implementation_names - .iter() - .map(|name| best_results.get(name).cloned().flatten()) - .collect::>(); - - let data_row = format!( - " - - {} - {} - - ", - core_count_results.core_count, - best_results_for_all_implementations - .into_iter() - .map(|result| { - if let Some(r) = result { - format!( - r#"{}"#, - r.tracker_info, - r.tracker_process_stats.avg_cpu_utilization, - r.average_responses, - ) - } else { - "-".to_string() - } - }) - .join("\n"), - ); - - data_rows.push(data_row); - } - - println!( - " - - - - - {} - - - - {} - -
CPU cores
- ", - all_implementation_names - .iter() - .map(|name| format!("{name}")) - .join("\n"), - data_rows.join("\n") - ) -}