@@ -17,24 +17,21 @@ use crate::executor::wall_time::perf::perf_executable::get_working_perf_executab
1717use crate :: prelude:: * ;
1818use anyhow:: Context ;
1919use fifo:: PerfFifo ;
20- use libc :: pid_t ;
20+ use parse_perf_file :: MemmapRecordsOutput ;
2121use perf_executable:: get_compression_flags;
2222use perf_executable:: get_event_flags;
23- use perf_map:: ProcessSymbols ;
2423use rayon:: prelude:: * ;
2524use runner_shared:: artifacts:: ArtifactExt ;
2625use runner_shared:: artifacts:: ExecutionTimestamps ;
2726use runner_shared:: debug_info:: ModuleDebugInfo ;
2827use runner_shared:: fifo:: Command as FifoCommand ;
2928use runner_shared:: fifo:: IntegrationMode ;
3029use runner_shared:: metadata:: PerfMetadata ;
31- use runner_shared:: unwind_data:: UnwindData ;
3230use std:: path:: Path ;
3331use std:: path:: PathBuf ;
3432use std:: { cell:: OnceCell , collections:: HashMap , process:: ExitStatus } ;
3533
3634mod jit_dump;
37- mod memory_mappings;
3835mod parse_perf_file;
3936mod setup;
4037
@@ -46,15 +43,10 @@ pub mod perf_map;
4643pub mod unwind_data;
4744
4845const PERF_METADATA_CURRENT_VERSION : u64 = 1 ;
49- const PERF_DATA_FILE_NAME : & str = "perf.data" ;
5046const PERF_PIPEDATA_FILE_NAME : & str = "perf.pipedata" ;
5147
5248pub struct PerfRunner {
5349 benchmark_data : OnceCell < BenchmarkData > ,
54- /// Whether to output the perf data to a streamable .pipedata file
55- /// This can be removed once we have upstreamed the the linux-perf-data crate changes to parse
56- /// from pipedata directly, to only support pipedata.
57- output_pipedata : bool ,
5850}
5951
6052impl PerfRunner {
@@ -89,9 +81,8 @@ impl PerfRunner {
8981 Ok ( ( ) )
9082 }
9183
92- pub fn new ( output_pipedata : bool ) -> Self {
84+ pub fn new ( ) -> Self {
9385 Self {
94- output_pipedata,
9586 benchmark_data : OnceCell :: new ( ) ,
9687 }
9788 }
@@ -160,36 +151,18 @@ impl PerfRunner {
160151 perf_fifo. ctl_path( ) . to_string_lossy( ) ,
161152 perf_fifo. ack_path( ) . to_string_lossy( )
162153 ) ,
154+ "-o" ,
155+ "-" , // Output to stdout for piping
156+ "--" ,
163157 ] ) ;
164158
165- if self . output_pipedata {
166- perf_wrapper_builder. args ( [
167- "-o" , "-" , // forces pipe mode
168- ] ) ;
169- } else {
170- perf_wrapper_builder. args ( [
171- "-o" ,
172- self . get_perf_file_path ( profile_folder)
173- . to_string_lossy ( )
174- . as_ref ( ) ,
175- ] ) ;
176- }
177-
178- perf_wrapper_builder. arg ( "--" ) ;
179159 cmd_builder. wrap_with ( perf_wrapper_builder) ;
180160
181- // Output the perf data to the profile folder
182- let perf_data_file_path = self . get_perf_file_path ( profile_folder) ;
183-
184- let raw_command = if self . output_pipedata {
185- format ! (
186- "set -o pipefail && {} | cat > {}" ,
187- & cmd_builder. as_command_line( ) ,
188- perf_data_file_path. to_string_lossy( )
189- )
190- } else {
191- cmd_builder. as_command_line ( )
192- } ;
161+ let raw_command = format ! (
162+ "set -o pipefail && {} | cat > {}" ,
163+ & cmd_builder. as_command_line( ) ,
164+ self . get_perf_file_path( profile_folder) . to_string_lossy( )
165+ ) ;
193166
194167 let mut wrapped_builder = CommandBuilder :: new ( "bash" ) ;
195168 wrapped_builder. args ( [ "-c" , & raw_command] ) ;
@@ -205,8 +178,7 @@ impl PerfRunner {
205178 let on_process_started = |mut child : std:: process:: Child | async move {
206179 // If we output pipedata, we do not parse the perf map during teardown yet, so we need to parse memory
207180 // maps as we receive the `CurrentBenchmark` fifo commands.
208- let ( data, exit_status) =
209- Self :: handle_fifo ( runner_fifo, perf_fifo, self . output_pipedata , & mut child) . await ?;
181+ let ( data, exit_status) = Self :: handle_fifo ( runner_fifo, perf_fifo, & mut child) . await ?;
210182 self . benchmark_data . set ( data) . unwrap_or_else ( |_| {
211183 error ! ( "Failed to set benchmark data in PerfRunner" ) ;
212184 } ) ;
@@ -247,12 +219,8 @@ impl PerfRunner {
247219 async fn handle_fifo (
248220 mut runner_fifo : RunnerFifo ,
249221 mut perf_fifo : PerfFifo ,
250- parse_memory_maps : bool ,
251222 child : & mut std:: process:: Child ,
252223 ) -> anyhow:: Result < ( BenchmarkData , std:: process:: ExitStatus ) > {
253- let mut symbols_by_pid = HashMap :: < pid_t , ProcessSymbols > :: new ( ) ;
254- let mut unwind_data_by_pid = HashMap :: < pid_t , Vec < UnwindData > > :: new ( ) ;
255-
256224 let on_cmd = async |cmd : & FifoCommand | {
257225 #[ allow( deprecated) ]
258226 match cmd {
@@ -262,19 +230,6 @@ impl PerfRunner {
262230 FifoCommand :: StopBenchmark => {
263231 perf_fifo. stop_events ( ) . await ?;
264232 }
265- FifoCommand :: CurrentBenchmark { pid, .. } => {
266- #[ cfg( target_os = "linux" ) ]
267- if parse_memory_maps
268- && !symbols_by_pid. contains_key ( pid)
269- && !unwind_data_by_pid. contains_key ( pid)
270- {
271- memory_mappings:: process_memory_mappings (
272- * pid,
273- & mut symbols_by_pid,
274- & mut unwind_data_by_pid,
275- ) ?;
276- }
277- }
278233 FifoCommand :: PingPerf => {
279234 if perf_fifo. ping ( ) . await . is_err ( ) {
280235 return Ok ( Some ( FifoCommand :: Err ) ) ;
@@ -299,27 +254,19 @@ impl PerfRunner {
299254 BenchmarkData {
300255 fifo_data,
301256 marker_result,
302- symbols_by_pid,
303- unwind_data_by_pid,
304257 } ,
305258 exit_status,
306259 ) )
307260 }
308261
309262 fn get_perf_file_path < P : AsRef < Path > > ( & self , profile_folder : P ) -> PathBuf {
310- if self . output_pipedata {
311- profile_folder. as_ref ( ) . join ( PERF_PIPEDATA_FILE_NAME )
312- } else {
313- profile_folder. as_ref ( ) . join ( PERF_DATA_FILE_NAME )
314- }
263+ profile_folder. as_ref ( ) . join ( PERF_PIPEDATA_FILE_NAME )
315264 }
316265}
317266
318267pub struct BenchmarkData {
319268 fifo_data : FifoBenchmarkData ,
320269 marker_result : ExecutionTimestamps ,
321- pub symbols_by_pid : HashMap < pid_t , ProcessSymbols > ,
322- pub unwind_data_by_pid : HashMap < pid_t , Vec < UnwindData > > ,
323270}
324271
325272#[ derive( Debug ) ]
@@ -336,28 +283,16 @@ impl BenchmarkData {
336283 ) -> Result < ( ) , BenchmarkDataSaveError > {
337284 self . marker_result . save_to ( & path) . unwrap ( ) ;
338285
339- let parsed_perf_map_output =
340- if self . symbols_by_pid . is_empty ( ) && self . unwind_data_by_pid . is_empty ( ) {
341- debug ! ( "Reading perf data from file for mmap extraction" ) ;
342- Some (
343- parse_perf_file:: parse_for_memmap2 ( perf_file_path) . map_err ( |e| {
344- error ! ( "Failed to parse perf file: {e}" ) ;
345- BenchmarkDataSaveError :: FailedToParsePerfFile
346- } ) ?,
347- )
348- } else {
349- None
350- } ;
351-
352- let ( symbols_by_pid, unwind_data_by_pid) =
353- if let Some ( parsed_perf_map_output) = parsed_perf_map_output. as_ref ( ) {
354- (
355- & parsed_perf_map_output. symbols_by_pid ,
356- & parsed_perf_map_output. unwind_data_by_pid ,
357- )
358- } else {
359- ( & self . symbols_by_pid , & self . unwind_data_by_pid )
360- } ;
286+ debug ! ( "Reading perf data from file for mmap extraction" ) ;
287+ let MemmapRecordsOutput {
288+ symbols_by_pid,
289+ unwind_data_by_pid,
290+ } = {
291+ parse_perf_file:: parse_for_memmap2 ( perf_file_path) . map_err ( |e| {
292+ error ! ( "Failed to parse perf file: {e}" ) ;
293+ BenchmarkDataSaveError :: FailedToParsePerfFile
294+ } ) ?
295+ } ;
361296
362297 let path_ref = path. as_ref ( ) ;
363298 debug ! ( "Saving symbols addresses" ) ;
0 commit comments