1 mod gnuplot_backend; 2 mod plotters_backend; 3 4 pub(crate) use gnuplot_backend::Gnuplot; 5 pub(crate) use plotters_backend::PlottersBackend; 6 7 use crate::estimate::Statistic; 8 use crate::measurement::ValueFormatter; 9 use crate::report::{BenchmarkId, ComparisonData, MeasurementData, ReportContext, ValueType}; 10 use std::path::PathBuf; 11 12 const REPORT_STATS: [Statistic; 7] = [ 13 Statistic::Typical, 14 Statistic::Slope, 15 Statistic::Mean, 16 Statistic::Median, 17 Statistic::MedianAbsDev, 18 Statistic::MedianAbsDev, 19 Statistic::StdDev, 20 ]; 21 const CHANGE_STATS: [Statistic; 2] = [Statistic::Mean, Statistic::Median]; 22 #[derive(Clone, Copy)] 23 pub(crate) struct PlotContext<'a> { 24 pub(crate) id: &'a BenchmarkId, 25 pub(crate) context: &'a ReportContext, 26 pub(crate) size: Option<(usize, usize)>, 27 pub(crate) is_thumbnail: bool, 28 } 29 30 impl<'a> PlotContext<'a> { size(mut self, s: Option<criterion_plot::Size>) -> PlotContext<'a>31 pub fn size(mut self, s: Option<criterion_plot::Size>) -> PlotContext<'a> { 32 if let Some(s) = s { 33 self.size = Some((s.0, s.1)); 34 } 35 self 36 } 37 thumbnail(mut self, value: bool) -> PlotContext<'a>38 pub fn thumbnail(mut self, value: bool) -> PlotContext<'a> { 39 self.is_thumbnail = value; 40 self 41 } 42 line_comparison_path(&self) -> PathBuf43 pub fn line_comparison_path(&self) -> PathBuf { 44 let mut path = self.context.output_directory.clone(); 45 path.push(self.id.as_directory_name()); 46 path.push("report"); 47 path.push("lines.svg"); 48 path 49 } 50 violin_path(&self) -> PathBuf51 pub fn violin_path(&self) -> PathBuf { 52 let mut path = self.context.output_directory.clone(); 53 path.push(self.id.as_directory_name()); 54 path.push("report"); 55 path.push("violin.svg"); 56 path 57 } 58 } 59 60 #[derive(Clone, Copy)] 61 pub(crate) struct PlotData<'a> { 62 pub(crate) formatter: &'a dyn ValueFormatter, 63 pub(crate) measurements: &'a MeasurementData<'a>, 64 pub(crate) comparison: Option<&'a ComparisonData>, 65 } 66 67 impl<'a> PlotData<'a> { comparison(mut self, comp: &'a ComparisonData) -> PlotData<'a>68 pub fn comparison(mut self, comp: &'a ComparisonData) -> PlotData<'a> { 69 self.comparison = Some(comp); 70 self 71 } 72 } 73 74 pub(crate) trait Plotter { pdf(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)75 fn pdf(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 76 regression(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)77 fn regression(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 78 iteration_times(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)79 fn iteration_times(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 80 abs_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)81 fn abs_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 82 rel_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)83 fn rel_distributions(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 84 line_comparison( &mut self, ctx: PlotContext<'_>, formatter: &dyn ValueFormatter, all_curves: &[&(&BenchmarkId, Vec<f64>)], value_type: ValueType, )85 fn line_comparison( 86 &mut self, 87 ctx: PlotContext<'_>, 88 formatter: &dyn ValueFormatter, 89 all_curves: &[&(&BenchmarkId, Vec<f64>)], 90 value_type: ValueType, 91 ); 92 violin( &mut self, ctx: PlotContext<'_>, formatter: &dyn ValueFormatter, all_curves: &[&(&BenchmarkId, Vec<f64>)], )93 fn violin( 94 &mut self, 95 ctx: PlotContext<'_>, 96 formatter: &dyn ValueFormatter, 97 all_curves: &[&(&BenchmarkId, Vec<f64>)], 98 ); 99 t_test(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>)100 fn t_test(&mut self, ctx: PlotContext<'_>, data: PlotData<'_>); 101 wait(&mut self)102 fn wait(&mut self); 103 } 104