@@ -15,7 +15,9 @@ mod integration_tests;
15
15
16
16
/// Builds and runs the specified Go project benchmarks, writing results to the .codspeed folder.
17
17
pub fn run_benchmarks ( project_dir : & Path , bench : & str ) -> anyhow:: Result < ( ) > {
18
- let binary_dir = project_dir. join ( ".codspeed" ) . join ( "walltime" ) ;
18
+ let profile_dir = std:: env:: var ( "CODSPEED_PROFILE_FOLDER" )
19
+ . context ( "CODSPEED_PROFILE_FOLDER env var not set" ) ?;
20
+ std:: fs:: remove_dir_all ( & profile_dir) . ok ( ) ;
19
21
20
22
// 1. Build phase - Benchmark and package discovery
21
23
let packages = BenchmarkPackage :: from_project ( project_dir) ?;
@@ -30,58 +32,32 @@ pub fn run_benchmarks(project_dir: &Path, bench: &str) -> anyhow::Result<()> {
30
32
31
33
let total_benchmarks: usize = packages. iter ( ) . map ( |p| p. benchmarks . len ( ) ) . sum ( ) ;
32
34
info ! ( "Total benchmarks discovered: {total_benchmarks}" ) ;
35
+ for ( name, path) in & bench_name_to_path {
36
+ info ! ( "Found {name:30} in {path:?}" ) ;
37
+ }
33
38
34
- debug ! ( "Creating binary directory: {binary_dir:?}" ) ;
35
- std:: fs:: create_dir_all ( & binary_dir) ?;
36
-
37
- // 2. Generate codspeed runners and build binaries
38
- let mut binaries = Vec :: new ( ) ;
39
+ // 2. Generate codspeed runners and execute them
39
40
for package in & packages {
40
- info ! ( "Processing package: {}" , package. name) ;
41
+ info ! ( "Generating custom runner for package: {}" , package. name) ;
41
42
let ( _target_dir, runner_path) = builder:: templater:: run ( package) ?;
42
43
43
- info ! ( "Building benchmarks for: {runner_path:?}" ) ;
44
- let binary_path = builder:: runner:: build ( & runner_path) ?;
45
-
46
- // Create a unique filename to avoid accidentally overwriting existing benchmarks.
47
- let filename = binary_path. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
48
- let unique_filename: String = format ! ( "{}_{:08x}" , filename, rand:: random:: <u32 >( ) ) ;
49
- let target_path = binary_dir. join ( unique_filename) ;
50
-
51
- debug ! ( "Copying {binary_path:?} to {target_path:?}" ) ;
52
- std:: fs:: copy ( binary_path, & target_path) ?;
53
- binaries. push ( target_path) ;
54
- }
55
-
56
- // 3. Run phase - Execute the built benchmarks
57
- for bench_path in & binaries {
58
- info ! ( "Running: {bench_path:?}" ) ;
59
-
60
- // Use a single iteration in tests to speed up execution, otherwise use 5 seconds
61
- let benchtime = if cfg ! ( test) { "1x" } else { "5s" } ;
62
-
63
- let cmd = std:: process:: Command :: new ( bench_path)
64
- . arg ( format ! ( "-test.bench={bench}" ) )
65
- . arg ( format ! ( "-test.benchtime={benchtime}" ) )
66
- . output ( )
67
- . context ( "Failed to execute benchmark command" ) ?;
68
-
69
- // Check if the command was successful
70
- if !cmd. status . success ( ) {
71
- let stdout = String :: from_utf8_lossy ( & cmd. stdout ) ;
72
- let stderr = String :: from_utf8_lossy ( & cmd. stderr ) ;
73
-
74
- warn ! ( "Command output: {stdout}" ) ;
75
- warn ! ( "Command error output: {stderr}" ) ;
76
-
77
- bail ! (
78
- "Failed to run benchmark: {bench_path:?}. Exit status: {}" ,
79
- cmd. status
80
- ) ;
81
- }
44
+ let args = [
45
+ "-test.bench" ,
46
+ bench,
47
+ // Use a single iteration in tests to speed up execution, otherwise use 5 seconds
48
+ "-test.benchtime" ,
49
+ if cfg ! ( test) || std:: env:: var ( "CODSPEED_ENV" ) . is_err ( ) {
50
+ "1x"
51
+ } else {
52
+ "5s"
53
+ } ,
54
+ ] ;
55
+
56
+ info ! ( "Running benchmarks for package: {}" , package. name) ;
57
+ builder:: runner:: run ( & runner_path, & args) ?;
82
58
}
83
59
84
- // 4 . Collect the results
60
+ // 3 . Collect the results
85
61
collect_walltime_results ( bench_name_to_path) ?;
86
62
87
63
Ok ( ( ) )
0 commit comments