Skip to content

Commit fccae2c

Browse files
committed
chore: use dir from env for runner fifo
1 parent ce7f6af commit fccae2c

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

crates/codspeed/src/fifo.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@ use std::path::{Path, PathBuf};
1212
// !!!!!!!!!!!!!!!!!!!!!!!!
1313
// Has to be in sync with `runner`.
1414
//
15-
pub const RUNNER_CTL_FIFO: &str = "/tmp/runner.ctl.fifo";
16-
pub const RUNNER_ACK_FIFO: &str = "/tmp/runner.ack.fifo";
15+
const RUNNER_CTL_FIFO_NAME: &str = "runner.ctl.fifo";
16+
const RUNNER_ACK_FIFO_NAME: &str = "runner.ack.fifo";
17+
18+
pub fn runner_fifo_dir() -> PathBuf {
19+
let raw_path =
20+
std::env::var("CODSPEED_FIFO_DIR").expect("CODSPEED_FIFO_DIR environment variable not set");
21+
PathBuf::from(raw_path)
22+
}
23+
24+
pub fn runner_ctl_fifo_path() -> PathBuf {
25+
runner_fifo_dir().join(RUNNER_CTL_FIFO_NAME)
26+
}
27+
28+
pub fn runner_ack_fifo_path() -> PathBuf {
29+
runner_fifo_dir().join(RUNNER_ACK_FIFO_NAME)
30+
}
1731

1832
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
1933
pub enum Command {
@@ -33,7 +47,7 @@ pub struct BenchGuard {
3347
}
3448

3549
impl BenchGuard {
36-
pub fn new(ctl_fifo: &str, ack_fifo: &str) -> anyhow::Result<Self> {
50+
pub fn new<P: Into<PathBuf>>(ctl_fifo: P, ack_fifo: P) -> anyhow::Result<Self> {
3751
let mut instance = Self {
3852
ctl_fifo: FifoIpc::connect(ctl_fifo)?.with_writer()?,
3953
ack_fifo: FifoIpc::connect(ack_fifo)?.with_reader()?,
@@ -58,10 +72,10 @@ impl Drop for BenchGuard {
5872
}
5973

6074
pub fn send_cmd(cmd: Command) -> anyhow::Result<()> {
61-
let mut writer = FifoIpc::connect(RUNNER_CTL_FIFO)?.with_writer()?;
75+
let mut writer = FifoIpc::connect(runner_ctl_fifo_path())?.with_writer()?;
6276
writer.send_cmd(cmd).unwrap();
6377

64-
let mut reader = FifoIpc::connect(RUNNER_ACK_FIFO)?.with_reader()?;
78+
let mut reader = FifoIpc::connect(runner_ack_fifo_path())?.with_reader()?;
6579
reader.wait_for_ack();
6680

6781
Ok(())

crates/divan_compat/divan_fork/src/bench/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl<'a> BenchContext<'a> {
658658
let bench_overheads = timer.bench_overheads();
659659

660660
use codspeed::fifo::*;
661-
let _guard = BenchGuard::new(RUNNER_CTL_FIFO, RUNNER_ACK_FIFO);
661+
let _guard = BenchGuard::new(runner_ctl_fifo_path(), runner_ack_fifo_path());
662662
while {
663663
// Conditions for when sampling is over:
664664
if elapsed_picos >= max_picos {

0 commit comments

Comments
 (0)