@@ -5,6 +5,7 @@ use crate::run::UnwindingMode;
55use crate :: run:: config:: Config ;
66use crate :: run:: runner:: helpers:: env:: is_codspeed_debug_enabled;
77use crate :: run:: runner:: helpers:: run_command_with_log_pipe:: run_command_with_log_pipe_and_callback;
8+ use crate :: run:: runner:: helpers:: run_with_sudo:: build_command_with_sudo;
89use crate :: run:: runner:: helpers:: run_with_sudo:: run_with_sudo;
910use crate :: run:: runner:: valgrind:: helpers:: ignored_objects_path:: get_objects_path_to_ignore;
1011use crate :: run:: runner:: valgrind:: helpers:: perf_maps:: harvest_perf_maps_for_pids;
@@ -24,8 +25,8 @@ use runner_shared::fifo::MarkerType;
2425use runner_shared:: metadata:: PerfMetadata ;
2526use runner_shared:: unwind_data:: UnwindData ;
2627use std:: collections:: HashSet ;
28+ use std:: fs:: canonicalize;
2729use std:: path:: { Path , PathBuf } ;
28- use std:: process:: Command ;
2930use std:: time:: Duration ;
3031use std:: { cell:: OnceCell , collections:: HashMap , process:: ExitStatus } ;
3132
@@ -84,12 +85,7 @@ impl PerfRunner {
8485 }
8586 }
8687
87- pub async fn run (
88- & self ,
89- mut cmd : Command ,
90- bench_cmd : & str ,
91- config : & Config ,
92- ) -> anyhow:: Result < ExitStatus > {
88+ pub async fn run ( & self , bench_cmd : Vec < String > , config : & Config ) -> anyhow:: Result < ExitStatus > {
9389 let perf_fifo = PerfFifo :: new ( ) ?;
9490 let runner_fifo = RunnerFifo :: new ( ) ?;
9591
@@ -111,11 +107,11 @@ impl PerfRunner {
111107 ( UnwindingMode :: Dwarf , None )
112108 } ;
113109
114- let cg_mode = match cg_mode {
115- UnwindingMode :: FramePointer => "fp" ,
116- UnwindingMode :: Dwarf => & format ! ( "dwarf,{}" , stack_size. unwrap_or( 8192 ) ) ,
110+ let cg_mode_str = match cg_mode {
111+ UnwindingMode :: FramePointer => "fp" . to_string ( ) ,
112+ UnwindingMode :: Dwarf => format ! ( "dwarf,{}" , stack_size. unwrap_or( 8192 ) ) ,
117113 } ;
118- debug ! ( "Using call graph mode: {cg_mode :?}" ) ;
114+ debug ! ( "Using call graph mode: {cg_mode_str :?}" ) ;
119115
120116 let quiet_flag = if !is_codspeed_debug_enabled ( ) {
121117 "--quiet"
@@ -126,6 +122,7 @@ impl PerfRunner {
126122 let working_perf_executable =
127123 get_working_perf_executable ( ) . context ( "Failed to find a working perf executable" ) ?;
128124
125+ let bench_str = bench_cmd. join ( " " ) ;
129126 let perf_args = [
130127 working_perf_executable. as_str ( ) ,
131128 "record" ,
@@ -138,20 +135,23 @@ impl PerfRunner {
138135 "--delay=-1" ,
139136 "-g" ,
140137 "--user-callchains" ,
141- & format ! ( "--call-graph={cg_mode }" ) ,
138+ & format ! ( "--call-graph={cg_mode_str }" ) ,
142139 & format ! (
143140 "--control=fifo:{},{}" ,
144141 perf_fifo. ctl_fifo_path. to_string_lossy( ) ,
145142 perf_fifo. ack_fifo_path. to_string_lossy( )
146143 ) ,
147144 & format ! ( "--output={PERF_DATA_PATH}" ) ,
148145 "--" ,
149- bench_cmd ,
146+ & bench_str ,
150147 ] ;
151-
152- cmd. args ( [ "sh" , "-c" , & perf_args. join ( " " ) ] ) ;
153- debug ! ( "cmd: {cmd:?}" ) ;
154-
148+ let perf_cmd = perf_args. join ( " " ) ;
149+ debug ! ( "raw perf cmd: {perf_cmd:?}" ) ;
150+ let mut cmd = build_command_with_sudo ( & [ "sh" , "-c" , & perf_cmd] ) ?;
151+ if let Some ( cwd) = & config. working_directory {
152+ let abs_cwd = canonicalize ( cwd) ?;
153+ cmd. current_dir ( abs_cwd) ;
154+ }
155155 let on_process_started = async |_| -> anyhow:: Result < ( ) > {
156156 let data = Self :: handle_fifo ( runner_fifo, perf_fifo) . await ?;
157157 let _ = self . benchmark_data . set ( data) ;
0 commit comments