File tree Expand file tree Collapse file tree
src/run/runner/wall_time/perf Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ use tempfile::TempDir;
2020use unwind_data:: UnwindData ;
2121
2222mod metadata;
23+ mod setup;
2324mod shared;
2425pub use shared:: * ;
2526
@@ -37,6 +38,8 @@ pub struct PerfRunner {
3738
3839impl PerfRunner {
3940 pub fn setup_environment ( ) -> anyhow:: Result < ( ) > {
41+ setup:: install_perf ( ) ?;
42+
4043 let sysctl_read = |name : & str | -> anyhow:: Result < i64 > {
4144 let output = std:: process:: Command :: new ( "sysctl" ) . arg ( name) . output ( ) ?;
4245 let output = String :: from_utf8 ( output. stdout ) ?;
@@ -191,7 +194,7 @@ impl PerfRunner {
191194 break ;
192195 }
193196
194- let result = tokio:: time:: timeout ( Duration :: from_secs ( 1 ) , runner_fifo. recv_cmd ( ) ) . await ;
197+ let result = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , runner_fifo. recv_cmd ( ) ) . await ;
195198 let Ok ( Ok ( cmd) ) = result else {
196199 continue ;
197200 } ;
Original file line number Diff line number Diff line change 1+ use crate :: { prelude:: * , run:: runner:: helpers:: setup:: run_with_sudo} ;
2+ use std:: process:: Command ;
3+
4+ fn cmd_version ( cmd : & str ) -> anyhow:: Result < String > {
5+ let is_installed = Command :: new ( "which" )
6+ . arg ( cmd)
7+ . output ( )
8+ . is_ok_and ( |output| output. status . success ( ) ) ;
9+ if !is_installed {
10+ bail ! ( "{cmd} is not installed" )
11+ }
12+
13+ Ok ( Command :: new ( cmd)
14+ . arg ( "--version" )
15+ . output ( )
16+ . map ( |out| String :: from_utf8_lossy ( & out. stdout ) . to_string ( ) ) ?)
17+ }
18+
19+ fn is_perf_installed ( ) -> bool {
20+ let version_str = cmd_version ( "perf" ) ;
21+ debug ! ( "Perf version: {:?}" , version_str) ;
22+
23+ version_str. is_ok ( )
24+ }
25+
26+ pub fn install_perf ( ) -> Result < ( ) > {
27+ if is_perf_installed ( ) {
28+ info ! ( "Perf is already installed, skipping installation" ) ;
29+ return Ok ( ( ) ) ;
30+ }
31+
32+ let cmd = Command :: new ( "uname" )
33+ . arg ( "-r" )
34+ . output ( )
35+ . expect ( "Failed to execute uname" ) ;
36+ let kernel_release = String :: from_utf8_lossy ( & cmd. stdout ) ;
37+ debug ! ( "Kernel release: {}" , kernel_release. trim( ) ) ;
38+
39+ debug ! ( "Installing perf" ) ;
40+ run_with_sudo ( & [ "apt-get" , "update" ] ) ?;
41+ run_with_sudo ( & [
42+ "apt-get" ,
43+ "install" ,
44+ "--allow-downgrades" ,
45+ "-y" ,
46+ "linux-tools-common" ,
47+ "linux-tools-generic" ,
48+ & format ! ( "linux-tools-{}" , kernel_release. trim( ) ) ,
49+ ] ) ?;
50+
51+ info ! ( "Perf installation completed successfully" ) ;
52+
53+ Ok ( ( ) )
54+ }
You can’t perform that action at this time.
0 commit comments