From 56b89d9cf710b01c7958382608fa36de46442a2a Mon Sep 17 00:00:00 2001 From: not-matthias Date: Mon, 7 Sep 2026 11:25:49 +0200 Subject: [PATCH 1/2] feat: add --memory-track-physical experimental flag Adds an experimental --memory-track-physical flag to `codspeed run` and `codspeed exec`, forwarded to the memtrack subprocess as CODSPEED_MEMTRACK_TRACK_PHYSICAL, matching the env var memtrack itself already reads (crates/memtrack/src/ebpf/tracker.rs). Falsey env values (0/false/no/off) are accepted so the flag can be set via env var without clap's strict true/false bool parsing rejecting it. --- src/cli/exec/mod.rs | 1 + src/cli/experimental.rs | 13 +++++++++++++ src/cli/run/mod.rs | 2 ++ src/executor/config.rs | 7 +++++++ src/executor/memory/executor.rs | 3 +++ 5 files changed, 26 insertions(+) diff --git a/src/cli/exec/mod.rs b/src/cli/exec/mod.rs index 4a757f74..a844cc6b 100644 --- a/src/cli/exec/mod.rs +++ b/src/cli/exec/mod.rs @@ -93,6 +93,7 @@ fn build_orchestrator_config( cycle_estimation: args.shared.cycle_estimation, exclude_allocations: args.shared.exclude_allocations, simulation_track_subprocess: args.shared.simulation_track_subprocess, + memory_track_physical: args.shared.experimental.experimental_memory_track_physical, }) } diff --git a/src/cli/experimental.rs b/src/cli/experimental.rs index 74aab817..336093b3 100644 --- a/src/cli/experimental.rs +++ b/src/cli/experimental.rs @@ -17,6 +17,16 @@ pub struct ExperimentalArgs { )] pub experimental_fair_sched: bool, + /// Enable physical (resident) memory tracking in memory mode. + #[arg( + long, + default_value_t = false, + help_heading = "Experimental", + env = "CODSPEED_MEMTRACK_TRACK_PHYSICAL", + value_parser = clap::builder::FalseyValueParser::new() + )] + pub experimental_memory_track_physical: bool, + /// Deprecated: cycle estimation is enabled by default and this flag has no effect. #[arg(long, hide = true, env = "CODSPEED_EXPERIMENTAL_CYCLE_ESTIMATION")] pub experimental_cycle_estimation: bool, @@ -33,6 +43,9 @@ impl ExperimentalArgs { if self.experimental_fair_sched { flags.push("--experimental-fair-sched"); } + if self.experimental_memory_track_physical { + flags.push("--experimental-memory-track-physical"); + } flags } diff --git a/src/cli/run/mod.rs b/src/cli/run/mod.rs index a218155c..414e04f8 100644 --- a/src/cli/run/mod.rs +++ b/src/cli/run/mod.rs @@ -83,6 +83,7 @@ impl RunArgs { experimental_fair_sched: false, experimental_cycle_estimation: false, experimental_exclude_allocations: false, + experimental_memory_track_physical: false, }, }, instruments: vec![], @@ -135,6 +136,7 @@ fn build_orchestrator_config( cycle_estimation: args.shared.cycle_estimation, exclude_allocations: args.shared.exclude_allocations, simulation_track_subprocess: args.shared.simulation_track_subprocess, + memory_track_physical: args.shared.experimental.experimental_memory_track_physical, }) } diff --git a/src/executor/config.rs b/src/executor/config.rs index 07f99c82..4675a078 100644 --- a/src/executor/config.rs +++ b/src/executor/config.rs @@ -98,6 +98,8 @@ pub struct OrchestratorConfig { /// Inherit valgrind's instrumentation state across a traced exec, so the cost of /// subprocesses spawned by a benchmark is measured too. pub simulation_track_subprocess: bool, + /// Enable physical (resident) memory tracking in memory mode. + pub memory_track_physical: bool, } /// Per-execution configuration passed to executors. @@ -138,6 +140,9 @@ pub struct ExecutorConfig { /// Inherit valgrind's instrumentation state across a traced exec, so the cost of /// subprocesses spawned by a benchmark is measured too. pub simulation_track_subprocess: bool, + /// Enable physical (resident) memory tracking in memory mode. Forwarded to + /// the memtrack subprocess as `CODSPEED_MEMTRACK_TRACK_PHYSICAL`. + pub memory_track_physical: bool, } #[derive(Debug, Clone, PartialEq)] @@ -210,6 +215,7 @@ impl OrchestratorConfig { cycle_estimation: self.cycle_estimation, exclude_allocations: self.exclude_allocations, simulation_track_subprocess: self.simulation_track_subprocess, + memory_track_physical: self.memory_track_physical, } } } @@ -245,6 +251,7 @@ impl OrchestratorConfig { cycle_estimation: true, exclude_allocations: false, simulation_track_subprocess: false, + memory_track_physical: false, } } } diff --git a/src/executor/memory/executor.rs b/src/executor/memory/executor.rs index b8c9a398..6cbb0f97 100644 --- a/src/executor/memory/executor.rs +++ b/src/executor/memory/executor.rs @@ -63,6 +63,9 @@ impl MemoryExecutor { // Build the memtrack command let mut cmd_builder = CommandBuilder::new(MEMTRACK_COMMAND); + if execution_context.config.memory_track_physical { + cmd_builder.env("CODSPEED_MEMTRACK_TRACK_PHYSICAL", "1"); + } cmd_builder.arg("track"); cmd_builder.arg("--output"); cmd_builder.arg(execution_context.profile_folder.join("results")); From ebc51dad144b26e830e957eb84034b656d11af91 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Mon, 7 Sep 2026 11:33:20 +0200 Subject: [PATCH 2/2] fix: silence dead-code lint on non-Linux for memory_track_physical MemoryExecutor (the only reader of ExecutorConfig::memory_track_physical) is compiled only on Linux, so macOS clippy (-D warnings) flags the field as dead code. --- src/executor/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/executor/config.rs b/src/executor/config.rs index 4675a078..39f95851 100644 --- a/src/executor/config.rs +++ b/src/executor/config.rs @@ -140,8 +140,10 @@ pub struct ExecutorConfig { /// Inherit valgrind's instrumentation state across a traced exec, so the cost of /// subprocesses spawned by a benchmark is measured too. pub simulation_track_subprocess: bool, - /// Enable physical (resident) memory tracking in memory mode. Forwarded to - /// the memtrack subprocess as `CODSPEED_MEMTRACK_TRACK_PHYSICAL`. + /// Enable physical (resident) memory tracking in memory mode. + /// + /// Only read by the memory executor, which is Linux-only. + #[cfg_attr(not(target_os = "linux"), allow(dead_code))] pub memory_track_physical: bool, }