Skip to content

Commit 4fdeebc

Browse files
not-matthiasart049
authored andcommitted
feat: install perf on setup
1 parent 476a551 commit 4fdeebc

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/run/runner/wall_time/perf/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use tempfile::TempDir;
2020
use unwind_data::UnwindData;
2121

2222
mod metadata;
23+
mod setup;
2324
mod shared;
2425
pub use shared::*;
2526

@@ -37,6 +38,8 @@ pub struct PerfRunner {
3738

3839
impl 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
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)