Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/exec-harness/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ pub fn perform(commands: Vec<BenchmarkCommand>, mode: MeasurementMode) -> Result
}

hooks.start_benchmark().unwrap();
let status = cmd.status();
let result = cmd.spawn().and_then(|mut child| {
let pid = child.id();
child.wait().map(|status| (pid, status))
});
hooks.stop_benchmark().unwrap();
let status = status.context("Failed to execute command")?;
let (pid, status) = result.context("Failed to execute command")?;

if !status.success() {
bail!("Command exited with non-zero status: {status}");
}

hooks.set_executed_benchmark(&name_and_uri.uri).unwrap();
hooks
.set_executed_benchmark_for_pid(pid, &name_and_uri.uri)
.unwrap();
}

Ok(())
Expand Down
18 changes: 16 additions & 2 deletions crates/instrument-hooks-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ mod linux_impl {

#[inline(always)]
pub fn set_executed_benchmark(&self, uri: &str) -> Result<(), u8> {
let pid = std::process::id() as i32;
self.set_executed_benchmark_for_pid(std::process::id(), uri)
}

/// Declares a benchmark that ran in the process `pid` rather than in this one.
#[inline(always)]
pub fn set_executed_benchmark_for_pid(&self, pid: u32, uri: &str) -> Result<(), u8> {
let c_uri = CString::new(uri).map_err(|_| 1u8)?;
let result = unsafe {
ffi::instrument_hooks_set_executed_benchmark(self.0, pid, c_uri.as_ptr())
ffi::instrument_hooks_set_executed_benchmark(self.0, pid as i32, c_uri.as_ptr())
};
if result == 0 { Ok(()) } else { Err(result) }
}
Expand Down Expand Up @@ -184,6 +189,10 @@ mod other_impl {
Ok(())
}

pub fn set_executed_benchmark_for_pid(&self, _pid: u32, _uri: &str) -> Result<(), u8> {
Ok(())
}

pub fn set_integration(&self, _name: &str, _version: &str) -> Result<(), u8> {
Ok(())
}
Expand Down Expand Up @@ -213,6 +222,11 @@ mod tests {
let hooks = InstrumentHooks::instance("test_integration", "1.0.0");
assert!(!hooks.is_instrumented() || hooks.start_benchmark().is_ok());
assert!(hooks.set_executed_benchmark("test_uri").is_ok());
assert!(
hooks
.set_executed_benchmark_for_pid(std::process::id() + 1, "test_uri")
.is_ok()
);
assert!(hooks.set_integration("test_integration", "1.0.0").is_ok());
let start = InstrumentHooks::current_timestamp();
let end = start + 1_000_000; // Simulate 1ms later
Expand Down
Loading