@@ -6,11 +6,7 @@ use crate::{
66} ;
77use anyhow:: Context ;
88use cargo_metadata:: { Metadata , Package } ;
9- use codspeed:: {
10- walltime:: get_raw_result_dir_from_workspace_root,
11- walltime_results:: { WalltimeBenchmark , WalltimeResults } ,
12- } ;
13- use glob:: glob;
9+ use codspeed:: walltime_results:: WalltimeResults ;
1410use std:: {
1511 io:: { self , Write } ,
1612 os:: unix:: process:: ExitStatusExt ,
@@ -105,7 +101,7 @@ pub fn run_benches(
105101 let codspeed_target_dir = get_codspeed_target_dir ( metadata, measurement_mode) ;
106102 let workspace_root = metadata. workspace_root . as_std_path ( ) ;
107103 if measurement_mode == MeasurementMode :: Walltime {
108- clear_raw_walltime_data ( workspace_root) ?;
104+ WalltimeResults :: clear ( workspace_root) ?;
109105 }
110106 let benches = filters. benches_to_run ( codspeed_target_dir, metadata) ?;
111107 if benches. is_empty ( ) {
@@ -183,35 +179,14 @@ pub fn run_benches(
183179 Ok ( ( ) )
184180}
185181
186- fn clear_raw_walltime_data ( workspace_root : & Path ) -> Result < ( ) > {
187- let raw_results_dir = get_raw_result_dir_from_workspace_root ( workspace_root) ;
188- std:: fs:: remove_dir_all ( & raw_results_dir) . ok ( ) ; // ignore errors when the directory does not exist
189- std:: fs:: create_dir_all ( & raw_results_dir) . context ( "Failed to create raw_results directory" ) ?;
190- Ok ( ( ) )
191- }
192-
193182fn aggregate_raw_walltime_data ( workspace_root : & Path ) -> Result < ( ) > {
194- // retrieve data from `{workspace_root}/target/codspeed/raw_results/{scope}/*.json
195- let walltime_benchmarks = glob ( & format ! (
196- "{}/**/*.json" ,
197- get_raw_result_dir_from_workspace_root( workspace_root)
198- . to_str( )
199- . unwrap( ) ,
200- ) ) ?
201- . map ( |sample| {
202- let sample = sample?;
203- let raw_walltime_data: codspeed:: walltime:: RawWallTimeData =
204- serde_json:: from_reader ( std:: fs:: File :: open ( & sample) ?) ?;
205- Ok ( WalltimeBenchmark :: from ( raw_walltime_data) )
206- } )
207- . collect :: < Result < Vec < _ > > > ( ) ?;
208-
209- if walltime_benchmarks. is_empty ( ) {
183+ let results = WalltimeResults :: collect_walltime_results ( workspace_root) ?;
184+ if results. benchmarks ( ) . is_empty ( ) {
210185 eprintln ! ( "No walltime benchmarks found" ) ;
211186 return Ok ( ( ) ) ;
212187 }
213188
214- for bench in & walltime_benchmarks {
189+ for bench in results . benchmarks ( ) {
215190 if bench. is_invalid ( ) {
216191 eprintln ! (
217192 "Warning: Benchmark {} was possibly optimized away" ,
@@ -226,7 +201,6 @@ fn aggregate_raw_walltime_data(workspace_root: &Path) -> Result<()> {
226201 . join ( "results" ) ;
227202 std:: fs:: create_dir_all ( & results_folder) . context ( "Failed to create results folder" ) ?;
228203
229- let results = WalltimeResults :: from_benchmarks ( walltime_benchmarks) ;
230204 let results_path = results_folder. join ( format ! ( "{}.json" , std:: process:: id( ) ) ) ;
231205 let mut results_file =
232206 std:: fs:: File :: create ( & results_path) . context ( "Failed to create results file" ) ?;
0 commit comments