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