Skip to content

Commit 150ff2f

Browse files
feat(exec-harness): use the new instrument-hooks bindings rather than codspeed core
1 parent b2494f3 commit 150ff2f

File tree

8 files changed

+37
-67
lines changed

8 files changed

+37
-67
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/exec-harness/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ name = "exec-harness"
1010
path = "src/main.rs"
1111

1212
[dependencies]
13+
instrument-hooks-bindings = { path = "../instrument-hooks-bindings" }
1314
anyhow = { workspace = true }
14-
codspeed = "4.2.0"
1515
log = { workspace = true }
1616
env_logger = { workspace = true }
1717
clap = { workspace = true }
@@ -23,7 +23,6 @@ tempfile = { workspace = true }
2323
object = { workspace = true }
2424

2525
[build-dependencies]
26-
cargo_metadata = "0.19"
2726
cc = "1"
2827

2928
[package.metadata.dist]

crates/exec-harness/build.rs

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
//! This script compiles the `libcodspeed_preload.so` shared library that is used
44
//! to inject instrumentation into child processes via LD_PRELOAD.
55
//!
6-
//! The library is built using the `core.c` and headers from the `codspeed` crate's
7-
//! `instrument-hooks` directory.
8-
//!
9-
//! # Environment Variables
10-
//!
11-
//! - `CODSPEED_INSTRUMENT_HOOKS_DIR`: Optional override for the instrument-hooks
12-
//! source directory. If not set, the build script will locate it from the
13-
//! `codspeed` crate in the cargo registry.
6+
//! The library is built using the `core.c` and headers from the `instrument-hooks-bindings`
7+
//! crate's `instrument-hooks` directory.
148
15-
use cargo_metadata::MetadataCommand;
169
use std::env;
1710
use std::path::PathBuf;
1811

@@ -25,7 +18,6 @@ struct PreloadConstants {
2518
/// Integration name reported to CodSpeed.
2619
integration_name: &'static str,
2720
/// Integration version reported to CodSpeed.
28-
/// This should match the version of the `codspeed` crate dependency.
2921
integration_version: &'static str,
3022
/// Filename for the preload shared library.
3123
preload_lib_filename: &'static str,
@@ -58,11 +50,11 @@ fn main() {
5850
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
5951

6052
// Try to get the instrument-hooks directory from the environment variable first,
61-
// otherwise locate it from the codspeed crate
62-
let instrument_hooks_dir = match env::var("CODSPEED_INSTRUMENT_HOOKS_DIR") {
63-
Ok(dir) => PathBuf::from(dir),
64-
Err(_) => find_codspeed_instrument_hooks_dir(),
65-
};
53+
// otherwise use the one from the instrument-hooks-bindings crate
54+
let instrument_hooks_dir = manifest_dir
55+
.parent()
56+
.unwrap()
57+
.join("instrument-hooks-bindings/instrument-hooks");
6658

6759
// Build the preload shared library
6860
let paths = PreloadBuildPaths {
@@ -130,40 +122,12 @@ fn build_shared_library(paths: &PreloadBuildPaths, constants: &PreloadConstants)
130122
}
131123
}
132124

133-
/// Find the instrument-hooks directory from the codspeed crate using cargo_metadata
134-
fn find_codspeed_instrument_hooks_dir() -> PathBuf {
135-
let metadata = MetadataCommand::new()
136-
.exec()
137-
.expect("Failed to run cargo metadata");
138-
139-
// Find the codspeed package in the resolved dependencies
140-
let codspeed_pkg = metadata
141-
.packages
142-
.iter()
143-
.find(|p| p.name == "codspeed")
144-
.expect("codspeed crate not found in dependencies");
145-
146-
let codspeed_dir = codspeed_pkg
147-
.manifest_path
148-
.parent()
149-
.expect("Failed to get codspeed crate directory");
150-
151-
let instrument_hooks_dir = codspeed_dir.join("instrument-hooks");
152-
153-
if !instrument_hooks_dir.exists() {
154-
panic!("instrument-hooks directory not found at {instrument_hooks_dir}");
155-
}
156-
157-
instrument_hooks_dir.into_std_path_buf()
158-
}
159-
160125
impl Default for PreloadConstants {
161-
// TODO(COD-1736): Stop impersonating codspeed-rust 🥸
162126
fn default() -> Self {
163127
Self {
164128
uri_env: "CODSPEED_BENCH_URI",
165-
integration_name: "codspeed-rust",
166-
integration_version: "4.2.0",
129+
integration_name: "exec-harness",
130+
integration_version: env!("CARGO_PKG_VERSION"),
167131
preload_lib_filename: "libcodspeed_preload.so",
168132
}
169133
}
@@ -185,13 +149,13 @@ impl PreloadBuildPaths {
185149
fn check_sources_exist(&self) {
186150
if !self.core_c.exists() {
187151
panic!(
188-
"core.c not found at {}. Make sure the codspeed crate is available.",
152+
"core.c not found at {}. Make sure the instrument-hooks-bindings crate is available.",
189153
self.core_c.display()
190154
);
191155
}
192156
if !self.includes_dir.exists() {
193157
panic!(
194-
"includes directory not found at {}. Make sure the codspeed crate is available.",
158+
"includes directory not found at {}. Make sure the instrument-hooks-bindings crate is available.",
195159
self.includes_dir.display()
196160
);
197161
}

crates/exec-harness/src/analysis/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
use crate::constants::INTEGRATION_NAME;
2+
use crate::constants::INTEGRATION_VERSION;
13
use crate::prelude::*;
24

35
use crate::BenchmarkCommand;
46
use crate::constants;
57
use crate::uri;
6-
use codspeed::instrument_hooks::InstrumentHooks;
8+
use instrument_hooks_bindings::InstrumentHooks;
79
use std::process::Command;
810

911
mod ld_preload_check;
1012
mod preload_lib_file;
1113

1214
pub fn perform(commands: Vec<BenchmarkCommand>) -> Result<()> {
13-
let hooks = InstrumentHooks::instance();
15+
let hooks = InstrumentHooks::instance(INTEGRATION_NAME, INTEGRATION_VERSION);
1416

1517
for benchmark_cmd in commands {
1618
let name_and_uri = uri::generate_name_and_uri(&benchmark_cmd.name, &benchmark_cmd.command);

crates/exec-harness/src/walltime/benchmark_loop.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::ExecutionOptions;
22
use super::config::RoundOrTime;
3+
use crate::constants::{INTEGRATION_NAME, INTEGRATION_VERSION};
34
use crate::prelude::*;
4-
use codspeed::instrument_hooks::InstrumentHooks;
5+
use instrument_hooks_bindings::InstrumentHooks;
56
use std::process::Command;
67
use std::time::Duration;
78

@@ -11,7 +12,7 @@ pub fn run_rounds(
1112
config: &ExecutionOptions,
1213
) -> Result<Vec<u128>> {
1314
let warmup_time_ns = config.warmup_time_ns;
14-
let hooks = InstrumentHooks::instance();
15+
let hooks = InstrumentHooks::instance(INTEGRATION_NAME, INTEGRATION_VERSION);
1516

1617
let do_one_round = || -> Result<(u64, u64)> {
1718
let mut child = Command::new(&command[0])

crates/exec-harness/src/walltime/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ mod config;
33

44
pub use config::ExecutionOptions;
55
pub use config::WalltimeExecutionArgs;
6+
use runner_shared::walltime_results::Creator;
67
use runner_shared::walltime_results::WalltimeBenchmark;
78
pub use runner_shared::walltime_results::WalltimeResults;
89

910
use crate::BenchmarkCommand;
11+
use crate::constants::INTEGRATION_NAME;
12+
use crate::constants::INTEGRATION_VERSION;
1013
use crate::prelude::*;
1114
use crate::uri::NameAndUri;
1215
use crate::uri::generate_name_and_uri;
@@ -42,8 +45,15 @@ pub fn perform(commands: Vec<BenchmarkCommand>) -> Result<()> {
4245
walltime_benchmarks.push(walltime_benchmark);
4346
}
4447

45-
let walltime_results = WalltimeResults::from_benchmarks(walltime_benchmarks)
46-
.expect("Failed to create walltime results");
48+
let walltime_results = WalltimeResults::new(
49+
Creator {
50+
name: INTEGRATION_NAME.to_string(),
51+
version: INTEGRATION_VERSION.to_string(),
52+
pid: std::process::id(),
53+
},
54+
walltime_benchmarks,
55+
)
56+
.expect("Failed to create walltime results");
4757

4858
walltime_results
4959
.save_to_file(

crates/instrument-hooks-bindings/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ mod linux_impl {
2727

2828
/// Returns a singleton instance of `InstrumentHooks`.
2929
#[inline(always)]
30-
pub fn instance() -> &'static Self {
30+
pub fn instance(integration: &str, version: &str) -> &'static Self {
3131
static INSTANCE: OnceLock<InstrumentHooks> = OnceLock::new();
3232
INSTANCE.get_or_init(|| {
3333
let instance =
3434
InstrumentHooks::new().expect("Failed to initialize InstrumentHooks");
3535
instance
36-
.set_integration("codspeed-rust", env!("CARGO_PKG_VERSION"))
36+
.set_integration(integration, version)
3737
.expect("Failed to set integration");
3838
instance
3939
})
@@ -210,7 +210,7 @@ mod tests {
210210

211211
#[test]
212212
fn test_instrument_hooks() {
213-
let hooks = InstrumentHooks::instance();
213+
let hooks = InstrumentHooks::instance("test_integration", "1.0.0");
214214
assert!(!hooks.is_instrumented() || hooks.start_benchmark().is_ok());
215215
assert!(hooks.set_executed_benchmark("test_uri").is_ok());
216216
assert!(hooks.set_integration("test_integration", "1.0.0").is_ok());

crates/runner-shared/src/walltime_results/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ mod stats;
44
pub use interfaces::*;
55

66
impl WalltimeResults {
7-
pub fn from_benchmarks(benchmarks: Vec<WalltimeBenchmark>) -> anyhow::Result<Self> {
7+
pub fn new(creator: Creator, benchmarks: Vec<WalltimeBenchmark>) -> anyhow::Result<Self> {
88
Ok(WalltimeResults {
99
instrument: Instrument {
1010
type_: "walltime".to_string(),
1111
},
12-
creator: Creator {
13-
// TODO(COD-1736): Stop impersonating codspeed-rust 🥸
14-
name: "codspeed-rust".to_string(),
15-
version: env!("CARGO_PKG_VERSION").to_string(),
16-
pid: std::process::id(),
17-
},
12+
creator,
1813
benchmarks,
1914
})
2015
}

0 commit comments

Comments
 (0)