Skip to content

Commit

Permalink
Plot runtime vs bandwidth too
Browse files Browse the repository at this point in the history
  • Loading branch information
heeckhau committed Mar 25, 2024
1 parent f5099fc commit 80764d5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 17 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
name: benchmark_graphs
path: |
./tlsn/benches/runtime_vs_latency.html
./tlsn/benches/runtime_vs_bandwidth.html
119 changes: 104 additions & 15 deletions tlsn/benches/bin/plot.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error>> {
let csv_file = std::env::args()
.nth(1)
Expand All @@ -14,9 +19,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rdr = csv::Reader::from_path(csv_file)?;

// Prepare data for plotting
let data: Vec<Vec<f32>> = rdr
let all_data = rdr
.deserialize::<Metrics>()
.collect::<Result<Vec<_>, _>>()? // 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<Metrics>) -> Result<Chart, Box<dyn std::error::Error>> {
const TITLE: &str = "Runtime vs Latency";

let data: Vec<Vec<f32>> = all_data
.into_iter()
.filter(|record| record.name == "latency")
.map(|record| {
Expand All @@ -25,12 +42,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.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()
Expand All @@ -52,17 +68,90 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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<Metrics>) -> Result<Chart, Box<dyn std::error::Error>> {
const TITLE: &str = "Runtime vs Bandwidth";

let download_data: Vec<Vec<f32>> = 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<Vec<f32>> = 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<Vec<f32>> = 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)
}

0 comments on commit 80764d5

Please sign in to comment.