@@ -3,14 +3,15 @@ use crate::prelude::*;
33use crate :: run:: RunnerMode ;
44use crate :: run:: instruments:: mongo_tracer:: MongoTracer ;
55use crate :: run:: runner:: executor:: Executor ;
6- use crate :: run:: runner:: helpers:: env:: get_base_injected_env;
6+ use crate :: run:: runner:: helpers:: env:: { get_base_injected_env, is_codspeed_debug_enabled } ;
77use crate :: run:: runner:: helpers:: get_bench_command:: get_bench_command;
88use crate :: run:: runner:: helpers:: run_command_with_log_pipe:: run_command_with_log_pipe;
99use crate :: run:: runner:: { ExecutorName , RunData } ;
1010use crate :: run:: { check_system:: SystemInfo , config:: Config } ;
1111use async_trait:: async_trait;
1212use std:: fs:: canonicalize;
1313use std:: process:: Command ;
14+ use tempfile:: NamedTempFile ;
1415
1516pub struct WallTimeExecutor {
1617 perf : Option < PerfRunner > ,
@@ -23,24 +24,37 @@ impl WallTimeExecutor {
2324 }
2425 }
2526
26- fn walltime_bench_cmd ( config : & Config , run_data : & RunData ) -> Result < String > {
27+ fn walltime_bench_cmd ( config : & Config , run_data : & RunData ) -> Result < ( NamedTempFile , String ) > {
2728 let bench_cmd = get_bench_command ( config) ?;
2829
29- // We have to forward all the environment variables.
3030 let system_env = std:: env:: vars ( )
31- . map ( |( env, value) | format ! ( "--setenv= {env}=\' {} \' " , value . replace ( "'" , " \" " ) ) )
32- . join ( " " ) ;
31+ . map ( |( env, value) | format ! ( "{env}={value}" ) )
32+ . join ( "\n " ) ;
3333
34- let setenv = get_base_injected_env ( RunnerMode :: Walltime , & run_data. profile_folder )
34+ let base_env = get_base_injected_env ( RunnerMode :: Walltime , & run_data. profile_folder )
3535 . into_iter ( )
36- . map ( |( env, value) | format ! ( "--setenv={env}={value}" ) )
37- . join ( " " ) ;
36+ . map ( |( env, value) | format ! ( "{env}={value}" ) )
37+ . join ( "\n " ) ;
38+
39+ // Store the environment variables in a file which we forward to the command.
40+ let env_file = NamedTempFile :: new ( ) ?;
41+ std:: fs:: write ( & env_file, format ! ( "{system_env}\n {base_env}" ) ) ?;
42+
3843 let uid = nix:: unistd:: Uid :: current ( ) . as_raw ( ) ;
3944 let gid = nix:: unistd:: Gid :: current ( ) . as_raw ( ) ;
40- Ok ( format ! (
41- "systemd-run --scope --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} {system_env} {setenv} -- sh -c '{}'" ,
45+
46+ let quiet_flag = if is_codspeed_debug_enabled ( ) {
47+ "--quiet"
48+ } else {
49+ ""
50+ } ;
51+
52+ let cmd = format ! (
53+ "systemd-run {quiet_flag} --pipe --collect --wait --slice=codspeed.slice --same-dir --uid={uid} --gid={gid} --property=EnvironmentFile={} -- sh -c '{}'" ,
54+ env_file. path( ) . display( ) ,
4255 bench_cmd. replace( "'" , "\" " )
43- ) )
56+ ) ;
57+ Ok ( ( env_file, cmd) )
4458 }
4559}
4660
@@ -72,7 +86,7 @@ impl Executor for WallTimeExecutor {
7286 cmd. current_dir ( abs_cwd) ;
7387 }
7488
75- let bench_cmd = Self :: walltime_bench_cmd ( config, run_data) ?;
89+ let ( _env_file , bench_cmd) = Self :: walltime_bench_cmd ( config, run_data) ?;
7690
7791 let status = if let Some ( perf) = & self . perf
7892 && config. enable_perf
0 commit comments