File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed
src/run/runner/wall_time/perf Expand file tree Collapse file tree 2 files changed +60
-1
lines changed 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 ) ?;
@@ -199,7 +202,7 @@ impl PerfRunner {
199202 break ;
200203 }
201204
202- let result = tokio:: time:: timeout ( Duration :: from_secs ( 1 ) , runner_fifo. recv_cmd ( ) ) . await ;
205+ let result = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , runner_fifo. recv_cmd ( ) ) . await ;
203206 let Ok ( Ok ( cmd) ) = result else {
204207 error ! ( "Recv cmd timeout" ) ;
205208 continue ;
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+ // TODO: Check for proper version
24+
25+ version_str. is_ok ( )
26+ }
27+
28+ pub fn install_perf ( ) -> Result < ( ) > {
29+ if is_perf_installed ( ) {
30+ info ! ( "Perf is already installed, skipping installation" ) ;
31+ return Ok ( ( ) ) ;
32+ }
33+
34+ let cmd = Command :: new ( "uname" )
35+ . arg ( "-r" )
36+ . output ( )
37+ . expect ( "Failed to execute uname" ) ;
38+ let kernel_release = String :: from_utf8_lossy ( & cmd. stdout ) ;
39+ debug ! ( "Kernel release: {}" , kernel_release. trim( ) ) ;
40+
41+ debug ! ( "Installing perf" ) ;
42+ run_with_sudo ( & [ "apt-get" , "update" ] ) ?;
43+ run_with_sudo ( & [
44+ "apt-get" ,
45+ "install" ,
46+ "--allow-downgrades" ,
47+ "-y" ,
48+ "linux-tools-common" ,
49+ "linux-tools-generic" ,
50+ & format ! ( "linux-tools-{}" , kernel_release. trim( ) ) ,
51+ ] ) ?;
52+
53+ info ! ( "Perf installation completed successfully" ) ;
54+
55+ Ok ( ( ) )
56+ }
You can’t perform that action at this time.
0 commit comments