Repository navigation
feat(cli): add walltime unwinding mode and stack sample size options #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,14 +228,38 @@ pub struct ProfilerRunArgs { | |
| pub enable_perf: Option<bool>, | ||
|
|
||
| #[command(flatten)] | ||
| pub perf: PerfRunArgs, | ||
| pub walltime: WalltimeRunArgs, | ||
| } | ||
|
|
||
| #[derive(Args, Debug, Clone)] | ||
| pub struct PerfRunArgs { | ||
| /// The unwinding mode that should be used with perf to collect the call stack. | ||
| #[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")] | ||
| pub struct WalltimeRunArgs { | ||
| /// The unwinding mode that the walltime profiler should use to collect the call stack. | ||
| #[arg(long, env = "CODSPEED_WALLTIME_UNWINDING_MODE")] | ||
| pub walltime_unwinding_mode: Option<UnwindingMode>, | ||
|
|
||
| /// Deprecated alias for --walltime-unwinding-mode / CODSPEED_WALLTIME_UNWINDING_MODE. | ||
| #[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE", hide = true)] | ||
| pub perf_unwinding_mode: Option<UnwindingMode>, | ||
|
|
||
| /// Size in bytes of the user stack copied with each sample for DWARF unwinding. | ||
| /// Larger values produce deeper call stacks but bigger profiles. | ||
| #[arg(long, env = "CODSPEED_WALLTIME_STACK_SAMPLE_SIZE")] | ||
| pub walltime_stack_sample_size: Option<u32>, | ||
| } | ||
|
|
||
| impl WalltimeRunArgs { | ||
| /// Resolves the effective unwinding mode, honoring the deprecated | ||
| /// `--perf-unwinding-mode` / `CODSPEED_PERF_UNWINDING_MODE` flag with a warning. | ||
| /// The new flag takes precedence when both are set. | ||
| pub fn resolve_unwinding_mode(&self) -> Option<UnwindingMode> { | ||
| let Some(legacy) = self.perf_unwinding_mode else { | ||
| return self.walltime_unwinding_mode; | ||
| }; | ||
| log::warn!( | ||
| "CODSPEED_PERF_UNWINDING_MODE / --perf-unwinding-mode is deprecated; use CODSPEED_WALLTIME_UNWINDING_MODE / --walltime-unwinding-mode instead." | ||
| ); | ||
|
Comment on lines
+258
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cli/shared.rs
Line: 258-260
Comment:
**Deprecation warning never appears**
Both `codspeed run` and `codspeed exec` call `resolve_unwinding_mode()` while building the config, before `Orchestrator::new()` installs the logger. This drops the warning, so users of `--perf-unwinding-mode` or `CODSPEED_PERF_UNWINDING_MODE` never learn about the replacement. Emit it after logger setup or use the existing startup-warning approach.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @not-matthias, this is a legit thing, and it's extremely annoying. We could create a dedicated issue and just |
||
| Some(self.walltime_unwinding_mode.unwrap_or(legacy)) | ||
|
Comment on lines
+254
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new precedence and stack-size overrides have no tests. Add focused cases for the old option alone, both options together, flag/environment combinations, and an explicit size overriding both the default and Python's inferred size. These are the main promises of this change; tests would catch later edits that silently send the wrong value to the profiler. Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cli/shared.rs
Line: 254-261
Comment:
**Option rules lack tests**
The new precedence and stack-size overrides have no tests. Add focused cases for the old option alone, both options together, flag/environment combinations, and an explicit size overriding both the default and Python's inferred size. These are the main promises of this change; tests would catch later edits that silently send the wrong value to the profiler.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we really care for this one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point — these tests are useful for regression protection but not essential to this change, so I’m withdrawing the suggestion. No action needed. |
||
| } | ||
| } | ||
|
|
||
| impl ProfilerRunArgs { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,8 +68,10 @@ pub struct OrchestratorConfig { | |
| pub modes: Vec<RunnerMode>, | ||
| pub instruments: Instruments, | ||
| pub enable_profiler: bool, | ||
| /// Stack unwinding mode for perf (if enabled) | ||
| pub perf_unwinding_mode: Option<UnwindingMode>, | ||
| /// Stack unwinding mode for the walltime profiler (if None, inferred from the command) | ||
| pub walltime_unwinding_mode: Option<UnwindingMode>, | ||
| /// User stack size in bytes copied per sample for DWARF unwinding (if None, profiler default) | ||
| pub walltime_stack_sample_size: Option<u32>, | ||
| /// Profiler override for walltime mode (if None, selected based on the platform) | ||
| pub walltime_profiler: Option<WalltimeProfiler>, | ||
|
|
||
|
|
@@ -120,8 +122,10 @@ pub struct ExecutorConfig { | |
|
|
||
| pub instruments: Instruments, | ||
| pub enable_profiler: bool, | ||
| /// Stack unwinding mode for perf (if enabled) | ||
| pub perf_unwinding_mode: Option<UnwindingMode>, | ||
| /// Stack unwinding mode for the walltime profiler (if None, inferred from the command) | ||
| pub walltime_unwinding_mode: Option<UnwindingMode>, | ||
| /// User stack size in bytes copied per sample for DWARF unwinding (if None, profiler default) | ||
| pub walltime_stack_sample_size: Option<u32>, | ||
|
Comment on lines
+125
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the separate flags for the cli, but here we could have them grouped? Cause technically the sample size makes no sense for fp etc, so even for clap it could make sense to parse it as an enum with two variants
|
||
|
|
||
| pub simulation_tool: SimulationTool, | ||
|
|
||
|
|
@@ -218,7 +222,8 @@ impl OrchestratorConfig { | |
| command, | ||
| instruments: self.instruments.clone(), | ||
| enable_profiler: self.enable_profiler, | ||
| perf_unwinding_mode: self.perf_unwinding_mode, | ||
| walltime_unwinding_mode: self.walltime_unwinding_mode, | ||
| walltime_stack_sample_size: self.walltime_stack_sample_size, | ||
| simulation_tool: self.simulation_tool, | ||
| skip_run: self.skip_run, | ||
| skip_setup: self.skip_setup, | ||
|
|
@@ -251,7 +256,8 @@ impl OrchestratorConfig { | |
| }], | ||
| modes: vec![RunnerMode::Simulation], | ||
| instruments: Instruments::test(), | ||
| perf_unwinding_mode: None, | ||
| walltime_unwinding_mode: None, | ||
| walltime_stack_sample_size: None, | ||
| walltime_profiler: None, | ||
| enable_profiler: false, | ||
| simulation_tool: SimulationTool::default(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,7 @@ impl Profiler for PerfProfiler { | |
| let perf_file_path = profile_folder.join(PERF_PIPEDATA_FILE_NAME); | ||
|
|
||
| // Infer the unwinding mode from the benchmark cmd | ||
| let (cg_mode, stack_size) = if let Some(mode) = config.perf_unwinding_mode { | ||
| let (cg_mode, stack_size) = if let Some(mode) = config.walltime_unwinding_mode { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the python/cargo/go tests: |
||
| (mode, None) | ||
| } else if command_has_executable( | ||
| &config.command, | ||
|
|
@@ -117,7 +117,13 @@ impl Profiler for PerfProfiler { | |
| suppress_go_perf_unwinding_warning(); | ||
| "fp" | ||
| } | ||
| UnwindingMode::Dwarf => &format!("dwarf,{}", stack_size.unwrap_or(8192)), | ||
| UnwindingMode::Dwarf => &format!( | ||
| "dwarf,{}", | ||
| config | ||
| .walltime_stack_sample_size | ||
| .or(stack_size) | ||
| .unwrap_or(8192) | ||
| ), | ||
| }; | ||
| debug!("Using call graph mode: {cg_mode:?}"); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| //! Samply profiler integration. | ||
|
|
||
| use crate::cli::InternalCommands; | ||
| #[cfg(target_os = "linux")] | ||
| use crate::cli::UnwindingMode; | ||
| use crate::cli::samply::SamplyArgs; | ||
| use crate::executor::ExecutorConfig; | ||
| use crate::executor::helpers::command::CommandBuilder; | ||
|
|
@@ -81,28 +83,42 @@ impl Profiler for SamplyProfiler { | |
| async fn wrap_command( | ||
| &mut self, | ||
| mut cmd_builder: CommandBuilder, | ||
| _config: &ExecutorConfig, | ||
| config: &ExecutorConfig, | ||
| profile_folder: &Path, | ||
| requires_sudo: bool, | ||
| ) -> anyhow::Result<CommandBuilder> { | ||
| let output_path = profile_folder.join(SAMPLY_OUTPUT_FILE_NAME); | ||
|
|
||
| // samply is bundled into this binary as the `samply` subcommand; | ||
| // re-exec ourselves so we don't depend on a system install. | ||
| let samply_builder = InternalCommands::Samply(SamplyArgs { | ||
| args: vec![ | ||
| "record".into(), | ||
| "--presymbolicate".into(), | ||
| "--no-open".into(), | ||
| "--save-only".into(), | ||
| "--rate".into(), | ||
| SAMPLING_RATE_HZ.to_string().into(), | ||
| "-o".into(), | ||
| output_path.clone().into(), | ||
| "--".into(), | ||
| ], | ||
| }) | ||
| .get_command_builder()?; | ||
| let mut args: Vec<std::ffi::OsString> = vec![ | ||
| "record".into(), | ||
| "--presymbolicate".into(), | ||
| "--no-open".into(), | ||
| "--save-only".into(), | ||
| "--rate".into(), | ||
| SAMPLING_RATE_HZ.to_string().into(), | ||
| "-o".into(), | ||
| output_path.clone().into(), | ||
| ]; | ||
| // Unwinding knobs are Linux-only in samply. | ||
| #[cfg(target_os = "linux")] | ||
| { | ||
| if let Some(mode) = config.walltime_unwinding_mode { | ||
| let mode = match mode { | ||
| UnwindingMode::FramePointer => "fp", | ||
| UnwindingMode::Dwarf => "dwarf", | ||
| }; | ||
| args.extend(["--unwinding-mode".into(), mode.into()]); | ||
| } | ||
| if let Some(size) = config.walltime_stack_sample_size { | ||
| args.extend(["--unwinding-stack-size".into(), size.to_string().into()]); | ||
| } | ||
|
Comment on lines
+107
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to check the implementation, but I'm 95% sure that in our samply fork we do both, so we should make sure we're not introducing unexpected behavior here |
||
| } | ||
| #[cfg(not(target_os = "linux"))] | ||
| let _ = config; | ||
| args.push("--".into()); | ||
| let samply_builder = InternalCommands::Samply(SamplyArgs { args }).get_command_builder()?; | ||
|
|
||
| cmd_builder.wrap_with(samply_builder); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could provide the default value per language here if we expect users/agents to use this now