11use crate :: walltime:: WalltimeResults ;
2+ use anyhow:: Context ;
3+ use anyhow:: Result ;
4+ use anyhow:: bail;
25use clap:: Parser ;
36use codspeed:: instrument_hooks:: InstrumentHooks ;
47use codspeed:: walltime_results:: WalltimeBenchmark ;
@@ -19,7 +22,7 @@ struct Args {
1922 command : Vec < String > ,
2023}
2124
22- fn main ( ) {
25+ fn main ( ) -> Result < ( ) > {
2326 let args = Args :: parse ( ) ;
2427
2528 if args. command . is_empty ( ) {
@@ -31,18 +34,15 @@ fn main() {
3134 let bench_name = args. name . unwrap_or_else ( || {
3235 // Extract filename from command path
3336 let cmd = & args. command [ 0 ] ;
34- std:: path:: Path :: new ( cmd)
35- . file_name ( )
36- . and_then ( |n| n. to_str ( ) )
37- . map ( |s| s. to_string ( ) )
38- . unwrap_or_else ( || "exec_benchmark" . to_string ( ) )
37+ std:: path:: Path :: new ( cmd) . to_string_lossy ( ) . into_owned ( )
3938 } ) ;
39+
4040 // TODO: Better URI generation
4141 let bench_uri = format ! ( "standalone_run::{bench_name}" ) ;
4242
4343 let hooks = InstrumentHooks :: instance ( ) ;
4444
45- // TODO: Change this to avoid impersonating ` codspeed-rust`
45+ // TODO: Stop impersonating codspeed-rust 🥸
4646 hooks
4747 . set_integration ( "codspeed-rust" , env ! ( "CARGO_PKG_VERSION" ) )
4848 . unwrap ( ) ;
@@ -53,36 +53,24 @@ fn main() {
5353 hooks. start_benchmark ( ) . unwrap ( ) ;
5454 for _ in 0 ..NUM_ITERATIONS {
5555 // Spawn the command
56- let mut child = match process:: Command :: new ( & args. command [ 0 ] )
56+ let mut child = process:: Command :: new ( & args. command [ 0 ] )
5757 . args ( & args. command [ 1 ..] )
5858 . spawn ( )
59- {
60- Ok ( child) => child,
61- Err ( e) => {
62- eprintln ! ( "Failed to spawn command: {e}" ) ;
63- process:: exit ( 1 ) ;
64- }
65- } ;
59+ . context ( "Failed to spawn command" ) ?;
60+
6661 // Start monotonic timer for this iteration
6762 let bench_start = InstrumentHooks :: current_timestamp ( ) ;
6863
6964 // Wait for the process to complete
70- let status = match child. wait ( ) {
71- Ok ( status) => status,
72- Err ( e) => {
73- eprintln ! ( "Failed to wait for command: {e}" ) ;
74- process:: exit ( 1 ) ;
75- }
76- } ;
65+ let status = child. wait ( ) . context ( "Failed to wait for command" ) ?;
7766
7867 // Measure elapsed time
7968 let bench_end = InstrumentHooks :: current_timestamp ( ) ;
8069 hooks. add_benchmark_timestamps ( bench_start, bench_end) ;
8170
8271 // Exit immediately if any iteration fails
8372 if !status. success ( ) {
84- eprintln ! ( "Command failed with exit code: {:?}" , status. code( ) ) ;
85- process:: exit ( status. code ( ) . unwrap_or ( 1 ) ) ;
73+ bail ! ( "Command failed with exit code: {:?}" , status. code( ) ) ;
8674 }
8775
8876 // Calculate and store the elapsed time in nanoseconds
@@ -113,4 +101,6 @@ fn main() {
113101 . unwrap_or_else ( |_| std:: env:: current_dir ( ) . unwrap ( ) . join ( ".codspeed" ) ) ,
114102 )
115103 . expect ( "Failed to save walltime results" ) ;
104+
105+ Ok ( ( ) )
116106}
0 commit comments