Skip to content

Commit ed290d3

Browse files
committed
feat: add perf support in walltime
1 parent 7b3a19c commit ed290d3

10 files changed

Lines changed: 307 additions & 60 deletions

File tree

Cargo.lock

Lines changed: 115 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ sysinfo = { version = "0.33.1", features = ["serde"] }
4646
indicatif = "0.17.8"
4747
console = "0.15.8"
4848
async-trait = "0.1.82"
49+
codspeed = { git = "https://github.com/CodspeedHQ/codspeed-rust", branch = "cod-674-collect-profiles-while-benchmarks-are-running", version = "=2.9.1" }
50+
libc = "0.2.171"
4951

5052
[dev-dependencies]
5153
temp-env = { version = "0.3.6", features = ["async_closure"] }

src/run/runner/helpers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod env;
22
pub mod get_bench_command;
33
pub mod profile_folder;
44
pub mod run_command_with_log_pipe;
5+
pub mod setup;

src/run/runner/helpers/run_command_with_log_pipe.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::process::Command;
66
use std::process::ExitStatus;
77
use std::thread;
88

9-
pub fn run_command_with_log_pipe(mut cmd: Command) -> Result<ExitStatus> {
9+
pub fn run_command_with_log_pipe_and_callback<F: FnOnce(u32)>(
10+
mut cmd: Command,
11+
cb: F,
12+
) -> Result<ExitStatus> {
1013
fn log_tee(
1114
mut reader: impl Read,
1215
mut writer: impl Write,
@@ -46,5 +49,13 @@ pub fn run_command_with_log_pipe(mut cmd: Command) -> Result<ExitStatus> {
4649
thread::spawn(move || {
4750
log_tee(stderr, std::io::stderr(), Some("[stderr]")).unwrap();
4851
});
52+
53+
let perf_pid = process.id();
54+
cb(perf_pid);
55+
4956
process.wait().context("failed to wait for the process")
5057
}
58+
59+
pub fn run_command_with_log_pipe(cmd: Command) -> Result<ExitStatus> {
60+
run_command_with_log_pipe_and_callback(cmd, |_| {})
61+
}

src/run/runner/helpers/setup.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::prelude::*;
2+
use anyhow::{anyhow, bail, Result};
3+
use log::{debug, info};
4+
use std::process::{Command, Stdio};
5+
6+
/// Run a command with sudo if available
7+
pub fn run_with_sudo(command_args: &[&str]) -> Result<()> {
8+
let use_sudo = Command::new("sudo")
9+
// `sudo true` will fail if sudo does not exist or the current user does not have sudo privileges
10+
.arg("true")
11+
.stdout(Stdio::null())
12+
.status()
13+
.is_ok_and(|status| status.success());
14+
let mut command_args: Vec<&str> = command_args.into();
15+
if use_sudo {
16+
command_args.insert(0, "sudo");
17+
}
18+
19+
debug!("Running command: {}", command_args.join(" "));
20+
let output = Command::new(command_args[0])
21+
.args(&command_args[1..])
22+
.stdout(Stdio::piped())
23+
.output()
24+
.map_err(|_| anyhow!("Failed to execute command: {}", command_args.join(" ")))?;
25+
26+
if !output.status.success() {
27+
info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
28+
error!("stderr: {}", String::from_utf8_lossy(&output.stderr));
29+
bail!("Failed to execute command: {}", command_args.join(" "));
30+
}
31+
32+
Ok(())
33+
}

src/run/runner/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::prelude::*;
55
use super::RunnerMode;
66

77
mod executor;
8-
mod helpers;
8+
pub(crate) mod helpers;
99
mod interfaces;
1010
mod valgrind;
1111
mod wall_time;

0 commit comments

Comments
 (0)