From 7d3186772cbae53dc5b5b8f40e526a778935e379 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 12 Jun 2024 00:06:36 +0800 Subject: [PATCH] feat!: remove csv_output (#33) --- Cargo.lock | 22 ---------- Cargo.toml | 8 +--- src/analysis/mod.rs | 2 - src/criterion.rs | 3 -- src/csv_report.rs | 95 ---------------------------------------- src/error.rs | 34 ++------------ src/lib.rs | 2 - src/report.rs | 12 ----- tests/criterion_tests.rs | 2 - 9 files changed, 4 insertions(+), 176 deletions(-) delete mode 100644 src/csv_report.rs diff --git a/Cargo.lock b/Cargo.lock index 13030d4..37f7d15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,7 +385,6 @@ dependencies = [ "ciborium", "codspeed", "colored", - "csv", "document-features", "futures", "num-traits", @@ -432,27 +431,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "csv" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" -dependencies = [ - "memchr", -] - [[package]] name = "document-features" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 2061307..8c04820 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ oorandom = "11.1.3" # Optional dependencies rayon = { version = "1.10", optional = true } -csv = { version = "1.3", optional = true } futures = { version = "0.3.30", default-features = false, optional = true } smol = { version = "2.0", default-features = false, optional = true } tokio = { version = "1.38.0", default-features = false, features = ["rt"], optional = true } @@ -58,7 +57,7 @@ futures = { version = "0.3.30", default-features = false, features = ["execut [features] default = ["cargo_bench_support", "rayon"] -stable = ["async_futures", "async_smol", "async_std", "async_tokio", "csv_output"] +stable = ["async_futures", "async_smol", "async_std", "async_tokio"] ## Enables [codspeed](https://codspeed.io) codspeed = ["dep:codspeed", "dep:colored"] @@ -79,11 +78,6 @@ async_std = ["async", "async-std"] # required in order to have Criterion.rs be usable outside of cargo-criterion. cargo_bench_support = [] -# This feature _currently_ does nothing, but in 0.4.0 it will be -# required in order to have Criterion.rs generate CSV files. This feature is deprecated in favor of -# cargo-criterion's --message-format=json option. -csv_output = ["csv"] - # Enable all of the async runtimes for the docs.rs output [package.metadata.docs.rs] features = ["async_futures", "async_smol", "async_std", "async_tokio"] diff --git a/src/analysis/mod.rs b/src/analysis/mod.rs index 07aa5ee..89209cc 100644 --- a/src/analysis/mod.rs +++ b/src/analysis/mod.rs @@ -336,6 +336,4 @@ fn copy_new_dir_to_base(id: &str, baseline: &str, output_directory: &Path) { try_else_return!(fs::cp(&new_dir.join("sample.json"), &base_dir.join("sample.json"))); try_else_return!(fs::cp(&new_dir.join("tukey.json"), &base_dir.join("tukey.json"))); try_else_return!(fs::cp(&new_dir.join("benchmark.json"), &base_dir.join("benchmark.json"))); - #[cfg(feature = "csv_output")] - try_else_return!(fs::cp(&new_dir.join("raw.csv"), &base_dir.join("raw.csv"))); } diff --git a/src/criterion.rs b/src/criterion.rs index 9d9ee31..5ae2a7c 100644 --- a/src/criterion.rs +++ b/src/criterion.rs @@ -63,7 +63,6 @@ impl Default for Criterion { cli: CliReport::new(false, false, CliVerbosity::Normal), bencher_enabled: false, bencher: BencherReport, - csv_enabled: cfg!(feature = "csv_output"), }; let mut criterion = Criterion { @@ -86,7 +85,6 @@ impl Default for Criterion { // disable all reports when connected to cargo-criterion; it will do the reporting. criterion.report.cli_enabled = false; criterion.report.bencher_enabled = false; - criterion.report.csv_enabled = false; } criterion } @@ -411,7 +409,6 @@ impl Criterion { // disable all reports when connected to cargo-criterion; it will do the reporting. self.report.cli_enabled = false; self.report.bencher_enabled = false; - self.report.csv_enabled = false; } else { match opts.output_format { OutputFormat::Bencher => { diff --git a/src/csv_report.rs b/src/csv_report.rs deleted file mode 100644 index 5334e05..0000000 --- a/src/csv_report.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::{io::Write, path::Path}; - -use csv::Writer; -use serde::Serialize; - -use crate::{ - error::Result, - measurement::ValueFormatter, - report::{BenchmarkId, MeasurementData, Report, ReportContext}, - Throughput, -}; - -#[derive(Serialize)] -struct CsvRow<'a> { - group: &'a str, - function: Option<&'a str>, - value: Option<&'a str>, - throughput_num: Option<&'a str>, - throughput_type: Option<&'a str>, - sample_measured_value: f64, - unit: &'static str, - iteration_count: u64, -} - -struct CsvReportWriter { - writer: Writer, -} -impl CsvReportWriter { - fn write_data( - &mut self, - id: &BenchmarkId, - data: &MeasurementData<'_>, - formatter: &dyn ValueFormatter, - ) -> Result<()> { - let mut data_scaled: Vec = data.sample_times().as_ref().into(); - let unit = formatter.scale_for_machines(&mut data_scaled); - let group = id.group_id.as_str(); - let function = id.function_id.as_deref(); - let value = id.value_str.as_deref(); - let (throughput_num, throughput_type) = match id.throughput { - Some(Throughput::Bytes(bytes)) => (Some(format!("{}", bytes)), Some("bytes")), - Some(Throughput::BytesDecimal(bytes)) => (Some(format!("{}", bytes)), Some("bytes")), - Some(Throughput::Elements(elems)) => (Some(format!("{}", elems)), Some("elements")), - None => (None, None), - }; - let throughput_num = throughput_num.as_deref(); - - for (count, measured_value) in data.iter_counts().iter().zip(data_scaled) { - let row = CsvRow { - group, - function, - value, - throughput_num, - throughput_type, - sample_measured_value: measured_value, - unit, - iteration_count: (*count) as u64, - }; - self.writer.serialize(row)?; - } - Ok(()) - } -} - -pub struct FileCsvReport; -impl FileCsvReport { - fn write_file( - &self, - path: &Path, - id: &BenchmarkId, - measurements: &MeasurementData<'_>, - formatter: &dyn ValueFormatter, - ) -> Result<()> { - let writer = Writer::from_path(path)?; - let mut writer = CsvReportWriter { writer }; - writer.write_data(id, measurements, formatter)?; - Ok(()) - } -} - -impl Report for FileCsvReport { - fn measurement_complete( - &self, - id: &BenchmarkId, - context: &ReportContext, - measurements: &MeasurementData<'_>, - formatter: &dyn ValueFormatter, - ) { - let mut path = context.output_directory.clone(); - path.push(id.as_directory_name()); - path.push("new"); - path.push("raw.csv"); - log_if_err!(self.write_file(&path, id, measurements, formatter)); - } -} diff --git a/src/error.rs b/src/error.rs index 6051162..1d4459b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,28 +1,13 @@ use std::{error::Error as StdError, fmt, io, path::PathBuf}; -#[cfg(feature = "csv_output")] -use csv::Error as CsvError; use serde_json::Error as SerdeError; #[allow(clippy::enum_variant_names)] #[derive(Debug)] pub enum Error { - AccessError { - path: PathBuf, - inner: io::Error, - }, - CopyError { - from: PathBuf, - to: PathBuf, - inner: io::Error, - }, - SerdeError { - path: PathBuf, - inner: SerdeError, - }, - #[cfg(feature = "csv_output")] - /// This API requires the following crate features to be activated: csv_output - CsvError(CsvError), + AccessError { path: PathBuf, inner: io::Error }, + CopyError { from: PathBuf, to: PathBuf, inner: io::Error }, + SerdeError { path: PathBuf, inner: SerdeError }, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -38,8 +23,6 @@ impl fmt::Display for Error { "Failed to read or write file {:?} due to serialization error: {}", path, inner ), - #[cfg(feature = "csv_output")] - Error::CsvError(inner) => write!(f, "CSV error: {}", inner), } } } @@ -49,8 +32,6 @@ impl StdError for Error { Error::AccessError { .. } => "AccessError", Error::CopyError { .. } => "CopyError", Error::SerdeError { .. } => "SerdeError", - #[cfg(feature = "csv_output")] - Error::CsvError(_) => "CsvError", } } @@ -59,19 +40,10 @@ impl StdError for Error { Error::AccessError { inner, .. } => Some(inner), Error::CopyError { inner, .. } => Some(inner), Error::SerdeError { inner, .. } => Some(inner), - #[cfg(feature = "csv_output")] - Error::CsvError(inner) => Some(inner), } } } -#[cfg(feature = "csv_output")] -impl From for Error { - fn from(other: CsvError) -> Error { - Error::CsvError(other) - } -} - pub type Result = ::std::result::Result; pub(crate) fn log_error(e: &Error) { diff --git a/src/lib.rs b/src/lib.rs index c6d6821..ba6822e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,8 +47,6 @@ mod bencher; mod cli; mod connection; mod criterion; -#[cfg(feature = "csv_output")] -mod csv_report; mod error; mod estimate; mod format; diff --git a/src/report.rs b/src/report.rs index 90d2c17..cc325b9 100644 --- a/src/report.rs +++ b/src/report.rs @@ -9,8 +9,6 @@ use std::{ use anes::{Attribute, ClearLine, Color, ResetAttributes, SetAttribute, SetForegroundColor}; use serde::{Deserialize, Serialize}; -#[cfg(feature = "csv_output")] -use crate::csv_report::FileCsvReport; use crate::{ estimate::{ChangeDistributions, ChangeEstimates, Distributions, Estimate, Estimates}, format, @@ -52,11 +50,6 @@ impl<'a> MeasurementData<'a> { pub fn iter_counts(&self) -> &Sample { self.data.x() } - - #[cfg(feature = "csv_output")] - pub fn sample_times(&self) -> &Sample { - self.data.y() - } } #[derive(Debug, Clone, Copy, Eq, PartialEq)] @@ -295,7 +288,6 @@ pub(crate) struct Reports { pub(crate) cli: CliReport, pub(crate) bencher_enabled: bool, pub(crate) bencher: BencherReport, - pub(crate) csv_enabled: bool, } macro_rules! reports_impl { (fn $name:ident(&self, $($argn:ident: $argt:ty),*)) => { @@ -306,10 +298,6 @@ macro_rules! reports_impl { if self.bencher_enabled { self.bencher.$name($($argn),*); } - #[cfg(feature = "csv_output")] - if self.csv_enabled { - FileCsvReport.$name($($argn),*); - } } }; } diff --git a/tests/criterion_tests.rs b/tests/criterion_tests.rs index e9a936c..e055b00 100644 --- a/tests/criterion_tests.rs +++ b/tests/criterion_tests.rs @@ -73,8 +73,6 @@ fn verify_stats(dir: &Path, baseline: &str) { verify_json(dir, &format!("{}/sample.json", baseline)); verify_json(dir, &format!("{}/tukey.json", baseline)); verify_json(dir, &format!("{}/benchmark.json", baseline)); - #[cfg(feature = "csv_output")] - verify_file(dir, &format!("{}/raw.csv", baseline)); } fn verify_not_exists(dir: &Path, path: &str) {