From 0d0f33daef8186e1c9cdc48763de28e3fa625fc3 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Thu, 26 Nov 2026 19:37:04 +0100 Subject: [PATCH] feat(walltime): add --walltime-sampling-rate option Perf and samply sampled at a hardcoded 997 Hz, so short functions get too few samples to read their share or change. Expose the rate as --walltime-sampling-rate / CODSPEED_WALLTIME_SAMPLING_RATE on run and exec, defaulting to 997 Hz, and forward it to both profilers. --- src/cli/exec/mod.rs | 5 +++++ src/cli/run/mod.rs | 7 +++++++ src/cli/shared.rs | 15 ++++++++++++++- src/executor/config.rs | 10 ++++++++++ src/executor/wall_time/profiler/mod.rs | 4 ---- src/executor/wall_time/profiler/perf/mod.rs | 3 +-- src/executor/wall_time/profiler/samply/mod.rs | 3 +-- 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/cli/exec/mod.rs b/src/cli/exec/mod.rs index 6d51f800e..1c1d82982 100644 --- a/src/cli/exec/mod.rs +++ b/src/cli/exec/mod.rs @@ -84,6 +84,11 @@ fn build_orchestrator_config( telemetry: false, }, walltime_unwinding: args.shared.profiler_run_args.walltime.resolve_unwinding(), + walltime_sampling_rate_hz: args + .shared + .profiler_run_args + .walltime + .walltime_sampling_rate_hz, enable_profiler: args.shared.profiler_run_args.resolve_enable_profiler(), walltime_profiler: args.shared.walltime_profiler, simulation_tool: args.shared.simulation_tool.unwrap_or_default(), diff --git a/src/cli/run/mod.rs b/src/cli/run/mod.rs index da59a76cd..1645cc10e 100644 --- a/src/cli/run/mod.rs +++ b/src/cli/run/mod.rs @@ -50,6 +50,7 @@ impl RunArgs { use super::experimental::ExperimentalArgs; use super::{ProfilerRunArgs, WalltimeRunArgs}; use crate::RunnerMode; + use crate::executor::config::DEFAULT_WALLTIME_SAMPLING_RATE_HZ; Self { shared: ExecAndRunSharedArgs { @@ -80,6 +81,7 @@ impl RunArgs { walltime: WalltimeRunArgs { walltime_unwinding_mode: None, perf_unwinding_mode: None, + walltime_sampling_rate_hz: DEFAULT_WALLTIME_SAMPLING_RATE_HZ, }, }, experimental: ExperimentalArgs { @@ -130,6 +132,11 @@ fn build_orchestrator_config( modes, instruments, walltime_unwinding: args.shared.profiler_run_args.walltime.resolve_unwinding(), + walltime_sampling_rate_hz: args + .shared + .profiler_run_args + .walltime + .walltime_sampling_rate_hz, enable_profiler: args.shared.profiler_run_args.resolve_enable_profiler(), walltime_profiler: args.shared.walltime_profiler, simulation_tool: args.shared.simulation_tool.unwrap_or_default(), diff --git a/src/cli/shared.rs b/src/cli/shared.rs index 863dea98b..0faffcd08 100644 --- a/src/cli/shared.rs +++ b/src/cli/shared.rs @@ -1,6 +1,8 @@ use super::experimental::ExperimentalArgs; use crate::VERSION; -use crate::executor::config::{SimulationTool, WalltimeProfiler, WalltimeUnwinding}; +use crate::executor::config::{ + DEFAULT_WALLTIME_SAMPLING_RATE_HZ, SimulationTool, WalltimeProfiler, WalltimeUnwinding, +}; use crate::prelude::*; use crate::run_environment::interfaces::RepositoryProvider; use crate::runner_mode::{RunnerMode, load_shell_session_mode}; @@ -242,6 +244,17 @@ pub struct WalltimeRunArgs { /// Deprecated alias for --walltime-unwinding-mode / CODSPEED_WALLTIME_UNWINDING_MODE. #[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE", hide = true, value_parser = parse_walltime_unwinding)] pub perf_unwinding_mode: Option, + + /// Walltime profiler samples per second. Higher rates give more samples for + /// short functions, at the cost of more profiling overhead. + #[arg( + long = "walltime-sampling-rate", + env = "CODSPEED_WALLTIME_SAMPLING_RATE", + value_name = "HZ", + default_value_t = DEFAULT_WALLTIME_SAMPLING_RATE_HZ, + value_parser = clap::value_parser!(u32).range(1..) + )] + pub walltime_sampling_rate_hz: u32, } impl WalltimeRunArgs { diff --git a/src/executor/config.rs b/src/executor/config.rs index 21d99bc44..6b2d53acb 100644 --- a/src/executor/config.rs +++ b/src/executor/config.rs @@ -9,6 +9,10 @@ use std::collections::HashMap; use std::path::PathBuf; use url::Url; +/// Default walltime profiler sampling rate (Hz). A prime number to avoid +/// synchronization with periodic tasks. +pub const DEFAULT_WALLTIME_SAMPLING_RATE_HZ: u32 = 997; + /// A benchmark target from project configuration. /// /// Defines how a benchmark is executed: @@ -92,6 +96,8 @@ pub struct OrchestratorConfig { pub enable_profiler: bool, /// Explicit unwinding settings; None preserves the profiler's automatic selection. pub walltime_unwinding: Option, + /// Walltime profiler samples per second. + pub walltime_sampling_rate_hz: u32, /// Profiler override for walltime mode (if None, selected based on the platform) pub walltime_profiler: Option, @@ -146,6 +152,8 @@ pub struct ExecutorConfig { pub enable_profiler: bool, /// Explicit unwinding settings; None preserves the profiler's automatic selection. pub walltime_unwinding: Option, + /// Walltime profiler samples per second. + pub walltime_sampling_rate_hz: u32, pub simulation_tool: SimulationTool, @@ -242,6 +250,7 @@ impl OrchestratorConfig { instruments: self.instruments.clone(), enable_profiler: self.enable_profiler, walltime_unwinding: self.walltime_unwinding, + walltime_sampling_rate_hz: self.walltime_sampling_rate_hz, simulation_tool: self.simulation_tool, skip_run: self.skip_run, skip_setup: self.skip_setup, @@ -276,6 +285,7 @@ impl OrchestratorConfig { modes: vec![RunnerMode::Simulation], instruments: Instruments::test(), walltime_unwinding: None, + walltime_sampling_rate_hz: DEFAULT_WALLTIME_SAMPLING_RATE_HZ, walltime_profiler: None, enable_profiler: false, simulation_tool: SimulationTool::default(), diff --git a/src/executor/wall_time/profiler/mod.rs b/src/executor/wall_time/profiler/mod.rs index b865c9cde..49cb406c7 100644 --- a/src/executor/wall_time/profiler/mod.rs +++ b/src/executor/wall_time/profiler/mod.rs @@ -10,10 +10,6 @@ mod unwinding; const WALLTIME_METADATA_CURRENT_VERSION: u64 = 1; -/// Sampling rate (Hz) shared by all walltime profilers. A prime number to -/// avoid synchronization with periodic tasks. -pub(super) const SAMPLING_RATE_HZ: u32 = 997; - /// Warning shown when walltime profiling ran but no benchmarks were detected. pub(super) const NO_BENCHMARKS_DETECTED_WARNING: &str = "Walltime profiling is enabled, but failed to detect benchmarks. \ If you wish to disable this warning, set CODSPEED_PROFILER_ENABLED=false"; diff --git a/src/executor/wall_time/profiler/perf/mod.rs b/src/executor/wall_time/profiler/perf/mod.rs index 0be24e615..5ae2a8e13 100644 --- a/src/executor/wall_time/profiler/perf/mod.rs +++ b/src/executor/wall_time/profiler/perf/mod.rs @@ -12,7 +12,6 @@ use crate::executor::shared::fifo::FifoBenchmarkData; use crate::executor::shared::module_artifacts::save_artifacts; use crate::executor::wall_time::profiler::NO_BENCHMARKS_DETECTED_WARNING; use crate::executor::wall_time::profiler::Profiler; -use crate::executor::wall_time::profiler::SAMPLING_RATE_HZ; use crate::executor::wall_time::profiler::WALLTIME_METADATA_CURRENT_VERSION; use crate::executor::wall_time::profiler::perf::perf_executable::get_working_perf_executable; use crate::executor::wall_time::profiler::unwinding::resolve_unwinding; @@ -123,7 +122,7 @@ impl Profiler for PerfProfiler { // Required for matching the markers and URIs to the samples. "-k", "CLOCK_MONOTONIC", - &format!("--freq={SAMPLING_RATE_HZ}"), + &format!("--freq={}", config.walltime_sampling_rate_hz), "--delay=-1", "-g", "--user-callchains", diff --git a/src/executor/wall_time/profiler/samply/mod.rs b/src/executor/wall_time/profiler/samply/mod.rs index 2eb9b9f76..a538255ef 100644 --- a/src/executor/wall_time/profiler/samply/mod.rs +++ b/src/executor/wall_time/profiler/samply/mod.rs @@ -23,7 +23,6 @@ use std::path::Path; use std::path::PathBuf; use super::NO_BENCHMARKS_DETECTED_WARNING; -use super::SAMPLING_RATE_HZ; use super::WALLTIME_METADATA_CURRENT_VERSION; const SAMPLY_OUTPUT_FILE_NAME: &str = "samply-profile.json.gz"; @@ -101,7 +100,7 @@ impl Profiler for SamplyProfiler { "--no-open".into(), "--save-only".into(), "--rate".into(), - SAMPLING_RATE_HZ.to_string().into(), + config.walltime_sampling_rate_hz.to_string().into(), "-o".into(), output_path.clone().into(), ];