Skip to content
Open
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
21 changes: 4 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tabled = { version = "0.20.0", features = ["ansi"] }
shell-words = "1.1.0"
rmp-serde = "1.3.0"
uuid = { version = "1.21.0", features = ["v4"] }
which = "8.0.2"

[target.'cfg(target_os = "linux")'.dependencies]
procfs = "0.17.0"
Expand Down
36 changes: 36 additions & 0 deletions crates/memtrack/src/allocators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,45 @@ pub struct AllocatorLib {
impl AllocatorLib {
pub fn find_all() -> anyhow::Result<Vec<AllocatorLib>> {
let mut allocators = static_linked::find_all()?;
allocators.extend(Self::find_from_env());
allocators.extend(dynamic::find_all()?);
Ok(allocators)
}

/// Discover allocators from binaries listed in the `CODSPEED_MEMTRACK_BINARIES` env var.
///
/// The variable is a colon-separated list of paths. Each path is checked for
/// a statically linked allocator via [`AllocatorLib::from_path_static`].
/// Invalid or missing paths are silently skipped (with a debug log).
fn find_from_env() -> Vec<AllocatorLib> {
let Ok(raw) = std::env::var("CODSPEED_MEMTRACK_BINARIES") else {
return vec![];
};

raw.split(':')
.filter(|p| !p.is_empty())
.filter_map(|p| {
let path = std::path::PathBuf::from(p);
match Self::from_path_static(&path) {
Ok(alloc) => {
log::debug!(
"Found {} allocator in env-specified binary: {}",
alloc.kind.name(),
path.display()
);
Some(alloc)
}
Err(e) => {
log::debug!(
"Skipping env-specified binary {}: {e}",
path.display()
);
None
}
}
})
.collect()
}
}

/// Check if a file is an ELF binary by reading its magic bytes.
Expand Down
35 changes: 35 additions & 0 deletions src/cli/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,41 @@ pub async fn execute_config(
codspeed_config: &CodSpeedConfig,
setup_cache_dir: Option<&Path>,
) -> Result<()> {
// Set CODSPEED_MEMTRACK_BINARIES so memtrack can discover statically linked
// allocators in exec target binaries (which may not live in known build dirs).
let memtrack_binaries: Vec<String> = config
.targets
.iter()
.filter_map(|t| match t {
executor::BenchmarkTarget::Exec { command, .. } => command.first().cloned(),
_ => None,
})
.filter_map(|bin| {
let result = match &config.working_directory {
Some(cwd) => which::which_in(&bin, std::env::var_os("PATH"), cwd),
None => which::which(&bin),
};
match result {
Ok(path) => Some(path.to_string_lossy().into_owned()),
Err(e) => {
debug!("Could not resolve exec binary {bin:?}: {e}");
None
}
}
})
.collect();

if !memtrack_binaries.is_empty() {
let mut all_paths = memtrack_binaries;
if let Ok(existing) = std::env::var("CODSPEED_MEMTRACK_BINARIES") {
if !existing.is_empty() {
all_paths.push(existing);
}
}
// SAFETY: The runner uses single-threaded tokio, so no concurrent env access.
unsafe { std::env::set_var("CODSPEED_MEMTRACK_BINARIES", all_paths.join(":")) };
}

let orchestrator = executor::Orchestrator::new(config, codspeed_config, api_client).await?;

if !orchestrator.is_local() {
Expand Down
Loading