Skip to content

Commit e270559

Browse files
feat(exec-harness): add support for analysis mode with memory instrument
1 parent 4d9b6b4 commit e270559

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::prelude::*;
2+
3+
use crate::uri::NameAndUri;
4+
use codspeed::instrument_hooks::InstrumentHooks;
5+
use std::process::Command;
6+
7+
pub fn perform(name_and_uri: NameAndUri, command: Vec<String>) -> Result<()> {
8+
let hooks = InstrumentHooks::instance();
9+
10+
let mut cmd = Command::new(&command[0]);
11+
cmd.args(&command[1..]);
12+
hooks.start_benchmark().unwrap();
13+
let status = cmd.status();
14+
hooks.stop_benchmark().unwrap();
15+
let status = status.context("Failed to execute command")?;
16+
17+
if !status.success() {
18+
bail!("Command exited with non-zero status: {status}");
19+
}
20+
21+
hooks.set_executed_benchmark(&name_and_uri.uri).unwrap();
22+
23+
Ok(())
24+
}

crates/exec-harness/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
use clap::ValueEnum;
2+
use serde::{Deserialize, Serialize};
3+
4+
pub mod analysis;
15
mod prelude;
26
pub mod uri;
37
pub mod walltime;
8+
9+
#[derive(ValueEnum, Clone, Debug, Serialize, Deserialize, PartialEq)]
10+
#[serde(rename_all = "lowercase")]
11+
pub enum MeasurementMode {
12+
Walltime,
13+
Memory,
14+
Simulation,
15+
}

crates/exec-harness/src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use anyhow::Result;
22
use anyhow::bail;
33
use clap::Parser;
4+
use exec_harness::MeasurementMode;
5+
use exec_harness::analysis;
46
use exec_harness::uri;
57
use exec_harness::walltime;
8+
use log::debug;
69

710
#[derive(Parser, Debug)]
811
#[command(name = "exec-harness")]
@@ -15,6 +18,10 @@ struct Args {
1518
#[arg(long)]
1619
name: Option<String>,
1720

21+
/// Set by the runner, should be coherent with the executor being used
22+
#[arg(short, long, global = true, env = "CODSPEED_RUNNER_MODE", hide = true)]
23+
measurement_mode: Option<MeasurementMode>,
24+
1825
#[command(flatten)]
1926
execution_args: walltime::WalltimeExecutionArgs,
2027

@@ -29,6 +36,8 @@ fn main() -> Result<()> {
2936
.format_timestamp(None)
3037
.init();
3138

39+
debug!("Starting exec-harness with pid {}", std::process::id());
40+
3241
let args = Args::parse();
3342

3443
if args.command.is_empty() {
@@ -37,10 +46,19 @@ fn main() -> Result<()> {
3746

3847
let bench_name_and_uri = uri::generate_name_and_uri(&args.name, &args.command);
3948

40-
// Build execution options from CLI args
41-
let execution_options: walltime::ExecutionOptions = args.execution_args.try_into()?;
49+
match args.measurement_mode {
50+
Some(MeasurementMode::Walltime) | None => {
51+
let execution_options: walltime::ExecutionOptions = args.execution_args.try_into()?;
4252

43-
walltime::perform(bench_name_and_uri, args.command, &execution_options)?;
53+
walltime::perform(bench_name_and_uri, args.command, &execution_options)?;
54+
}
55+
Some(MeasurementMode::Memory) => {
56+
analysis::perform(bench_name_and_uri, args.command)?;
57+
}
58+
Some(MeasurementMode::Simulation) => {
59+
bail!("Simulation measurement mode is not yet supported by exec-harness");
60+
}
61+
}
4462

4563
Ok(())
4664
}

0 commit comments

Comments
 (0)