use std::{any::Any, fmt, sync::Arc};
use serde::{Deserialize, Serialize};
pub(crate) use self::{
printer::{PrintingReporter, Verbosity},
seq::SeqReporter,
};
use crate::{BenchmarkId, CachegrindStats, cachegrind::CachegrindOutput};
pub(crate) mod baseline;
mod printer;
mod seq;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BenchmarkOutput {
pub stats: CachegrindOutput,
pub prev_stats: Option<CachegrindOutput>,
}
#[allow(unused_variables)]
pub trait Reporter: fmt::Debug {
fn set_logger(&mut self, logger: &Arc<dyn Logger>) {
}
fn new_test(&mut self, id: &BenchmarkId) -> Box<dyn TestReporter> {
Box::new(())
}
fn new_benchmark(&mut self, id: &BenchmarkId) -> Box<dyn BenchmarkReporter>;
fn ok(self: Box<Self>) {
}
}
pub trait Logger: Send + Sync + fmt::Debug {
fn debug(&self, debug_info: &dyn fmt::Display);
fn warning(&self, warning: &dyn fmt::Display);
fn fatal(&self, error: &dyn fmt::Display) -> !;
fn for_benchmark(self: Arc<Self>, id: &BenchmarkId) -> Arc<dyn Logger>;
}
impl Logger for () {
fn debug(&self, _debug_info: &dyn fmt::Display) {
}
fn warning(&self, _warning: &dyn fmt::Display) {
}
fn fatal(&self, error: &dyn fmt::Display) -> ! {
panic!("{error}");
}
fn for_benchmark(self: Arc<Self>, _id: &BenchmarkId) -> Arc<dyn Logger> {
self
}
}
pub trait TestReporter {
fn ok(self: Box<Self>);
fn fail(self: Box<Self>, panic_data: &dyn Any);
}
impl TestReporter for () {
fn ok(self: Box<Self>) {
}
fn fail(self: Box<Self>, _panic_data: &dyn Any) {
}
}
#[allow(unused_variables)]
pub trait BenchmarkReporter: Send + fmt::Debug {
fn start_execution(&mut self) {
}
#[doc(hidden)] fn baseline_computed(&mut self, stats: &CachegrindStats) {
}
fn ok(self: Box<Self>, output: &BenchmarkOutput);
}