From 80764d5e43ec9c468292e3eb237595777f867444 Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Mon, 25 Mar 2024 16:52:06 +0100 Subject: [PATCH] Plot runtime vs bandwidth too --- .github/workflows/bench.yml | 6 +- tlsn/benches/bin/plot.rs | 119 +++++++++++++++++++++++++++++++----- 2 files changed, 108 insertions(+), 17 deletions(-) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 1171ce403..4cc7bfe4c 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -23,5 +23,7 @@ jobs: - name: Upload runtime_vs_latency.html uses: actions/upload-artifact@v4 with: - name: runtime_vs_latency - path: ./tlsn/benches/runtime_vs_latency.html \ No newline at end of file + name: benchmark_graphs + path: | + ./tlsn/benches/runtime_vs_latency.html + ./tlsn/benches/runtime_vs_bandwidth.html diff --git a/tlsn/benches/bin/plot.rs b/tlsn/benches/bin/plot.rs index 5c04502be..dd72fd0a2 100644 --- a/tlsn/benches/bin/plot.rs +++ b/tlsn/benches/bin/plot.rs @@ -1,11 +1,16 @@ use charming::{ - component::{Axis, DataView, Feature, Restore, SaveAsImage, Title, Toolbox, ToolboxDataZoom}, - element::{NameLocation, Tooltip, Trigger}, - series::Scatter, - Chart, HtmlRenderer, ImageRenderer, + component::{ + Axis, DataView, Feature, Legend, Restore, SaveAsImage, Title, Toolbox, ToolboxDataZoom, + }, + element::{NameLocation, Orient, Tooltip, Trigger}, + series::{Line, Scatter}, + theme::Theme, + Chart, HtmlRenderer, }; use tlsn_benches::metrics::Metrics; +const THEME: Theme = Theme::Default; + fn main() -> Result<(), Box> { let csv_file = std::env::args() .nth(1) @@ -14,9 +19,21 @@ fn main() -> Result<(), Box> { let mut rdr = csv::Reader::from_path(csv_file)?; // Prepare data for plotting - let data: Vec> = rdr + let all_data = rdr .deserialize::() .collect::, _>>()? // Attempt to collect all results, return an error if any fail + ; + + let _chart = runtime_vs_latency(&all_data)?; + let _chart = runtime_vs_bandwidth(&all_data)?; + + Ok(()) +} + +fn runtime_vs_latency(all_data: &Vec) -> Result> { + const TITLE: &str = "Runtime vs Latency"; + + let data: Vec> = all_data .into_iter() .filter(|record| record.name == "latency") .map(|record| { @@ -25,12 +42,11 @@ fn main() -> Result<(), Box> { }) .collect(); - const TITLE: &str = "Runtime vs Latency"; - // https://github.com/yuankunzhang/charming let chart = Chart::new() - .title(Title::new().text(TITLE).left("center").top(0)) + .title(Title::new().text(TITLE)) .tooltip(Tooltip::new().trigger(Trigger::Axis)) + .legend(Legend::new().orient(Orient::Vertical)) .toolbox( Toolbox::new().show(true).feature( Feature::new() @@ -52,17 +68,90 @@ fn main() -> Result<(), Box> { .name("Runtime (s)") .name_location(NameLocation::Middle), ) - .series(Scatter::new().symbol_size(10).data(data)); + .series( + Scatter::new() + .name("Combined Latency") + .symbol_size(10) + .data(data), + ); // Save the chart as HTML file. - let mut html_renderer = HtmlRenderer::new(TITLE, 1000, 800); - html_renderer + HtmlRenderer::new(TITLE, 1000, 800) + .theme(THEME) .save(&chart, "runtime_vs_latency.html") .unwrap(); - // Save the chart as SVG file. - let mut renderer = ImageRenderer::new(1000, 800); - let _ = renderer.save(&chart, "runtime_vs_latency.svg"); + Ok(chart) +} - Ok(()) +fn runtime_vs_bandwidth(all_data: &Vec) -> Result> { + const TITLE: &str = "Runtime vs Bandwidth"; + + let download_data: Vec> = all_data + .into_iter() + .filter(|record| record.name == "download_bandwidth") + .map(|record| vec![record.download as f32, record.runtime as f32]) + .collect(); + let upload_deferred_data: Vec> = all_data + .into_iter() + .filter(|record| record.name == "upload_bandwidth" && record.defer_decryption) + .map(|record| vec![record.upload as f32, record.runtime as f32]) + .collect(); + let upload_non_deferred_data: Vec> = all_data + .into_iter() + .filter(|record| record.name == "upload_bandwidth" && !record.defer_decryption) + .map(|record| vec![record.upload as f32, record.runtime as f32]) + .collect(); + + // https://github.com/yuankunzhang/charming + let chart = Chart::new() + .title(Title::new().text(TITLE)) + .tooltip(Tooltip::new().trigger(Trigger::Axis)) + .legend(Legend::new().orient(Orient::Vertical)) + .toolbox( + Toolbox::new().show(true).feature( + Feature::new() + .save_as_image(SaveAsImage::new()) + .restore(Restore::new()) + .data_zoom(ToolboxDataZoom::new().y_axis_index("none")) + .data_view(DataView::new().read_only(false)), + ), + ) + .x_axis( + Axis::new() + .scale(true) + .name("Bandwidth (Mbps)") + .name_location(NameLocation::Center), + ) + .y_axis( + Axis::new() + .scale(true) + .name("Runtime (s)") + .name_location(NameLocation::Middle), + ) + .series( + Line::new() + .name("Download bandwidth") + .symbol_size(10) + .data(download_data), + ) + .series( + Line::new() + .name("Upload bandwidth (deferred decryption)") + .symbol_size(10) + .data(upload_deferred_data), + ) + .series( + Line::new() + .name("Upload bandwidth") + .symbol_size(10) + .data(upload_non_deferred_data), + ); + // Save the chart as HTML file. + HtmlRenderer::new(TITLE, 1000, 800) + .theme(THEME) + .save(&chart, "runtime_vs_bandwidth.html") + .unwrap(); + + Ok(chart) }