@@ -6,6 +6,7 @@ use crate::BenchmarkCommand;
66use crate :: constants;
77use crate :: uri;
88use instrument_hooks_bindings:: InstrumentHooks ;
9+ use std:: path:: PathBuf ;
910use std:: process:: Command ;
1011
1112mod ld_preload_check;
@@ -57,7 +58,11 @@ pub fn perform_with_valgrind(commands: Vec<BenchmarkCommand>) -> Result<()> {
5758 cmd. env ( "PYTHONPERFSUPPORT" , "1" ) ;
5859 cmd. env ( constants:: URI_ENV , & name_and_uri. uri ) ;
5960
60- let status = cmd. status ( ) . context ( "Failed to execute command" ) ?;
61+ let mut child = cmd. spawn ( ) . context ( "Failed to spawn command" ) ?;
62+
63+ let status = child. wait ( ) . context ( "Failed to execute command" ) ?;
64+
65+ bail_if_command_spawned_subprocesses_under_valgrind ( child. id ( ) ) ?;
6166
6267 if !status. success ( ) {
6368 bail ! ( "Command exited with non-zero status: {status}" ) ;
@@ -66,3 +71,35 @@ pub fn perform_with_valgrind(commands: Vec<BenchmarkCommand>) -> Result<()> {
6671
6772 Ok ( ( ) )
6873}
74+
75+ fn bail_if_command_spawned_subprocesses_under_valgrind ( pid : u32 ) -> Result < ( ) > {
76+ let Some ( profile_folder) = std:: env:: var_os ( "CODSPEED_PROFILE_FOLDER" ) else {
77+ debug ! ( "CODSPEED_PROFILE_FOLDER is not set, skipping subprocess detection" ) ;
78+ return Ok ( ( ) ) ;
79+ } ;
80+
81+ let profile_folder = PathBuf :: from ( profile_folder) ;
82+
83+ // Bail if any <pid>.out where <pid> > pid of the benchmark process exists in the profile
84+ // folder, which indicates that the benchmark process spawned subprocesses.
85+ for entry in std:: fs:: read_dir ( profile_folder) ? {
86+ let entry = entry?;
87+ let file_name = entry. file_name ( ) ;
88+ let file_name = file_name. to_string_lossy ( ) ;
89+
90+ if let Some ( stripped) = file_name. strip_suffix ( ".out" ) {
91+ if let Ok ( subprocess_pid) = stripped. parse :: < u32 > ( ) {
92+ if subprocess_pid > pid {
93+ bail ! (
94+ "The codspeed CLI in CPU Simulation mode does not support measuring processes that spawn other processes yet.\n \n \
95+ Please either:\n \
96+ - Use the walltime measurement mode, or\n \
97+ - Benchmark a process that does not create subprocesses"
98+ )
99+ }
100+ }
101+ }
102+ }
103+
104+ Ok ( ( ) )
105+ }
0 commit comments