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 ) ?;
@@ -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+
22+ // TODO: Check for proper version
23+
24+ version_str. is_ok ( )
25+ }
26+
27+ pub fn install_perf ( ) -> Result < ( ) > {
28+ if is_perf_installed ( ) {
29+ info ! ( "Perf is already installed, skipping installation" ) ;
30+ return Ok ( ( ) ) ;
31+ }
32+
33+ debug ! ( "Installing perf" ) ;
34+
35+ run_with_sudo ( & [ "apt-get" , "update" ] ) ?;
36+ run_with_sudo ( & [
37+ "apt-get" ,
38+ "install" ,
39+ "--allow-downgrades" ,
40+ "-y" ,
41+ "linux-tools-common linux-tools-generic linux-tools-$(uname -r)" ,
42+ ] ) ?;
43+
44+ info ! ( "Perf installation completed successfully" ) ;
45+
46+ Ok ( ( ) )
47+ }
You can’t perform that action at this time.
0 commit comments