-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add samply profiler support #338
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
009bff1
2fcc338
c288d7d
d6952bb
1b90106
2ebfba2
7754c25
5a50e38
2486f84
d27d3cd
ed91edd
d3d27f4
9a2ab1b
1fe921c
f1fa303
8bbdf4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| use clap::Parser; | ||
|
|
||
| use crate::prelude::*; | ||
|
|
||
| /// Run the bundled samply profiler. Arguments after `samply` are forwarded | ||
| /// verbatim to samply's own CLI parser. | ||
| #[derive(Debug, clap::Args)] | ||
| pub struct SamplyArgs { | ||
| #[arg(trailing_var_arg = true, allow_hyphen_values = true)] | ||
| args: Vec<std::ffi::OsString>, | ||
| } | ||
|
|
||
| pub fn run(args: SamplyArgs) -> Result<()> { | ||
| use ::samply::cli; | ||
|
|
||
| let argv = std::iter::once(std::ffi::OsString::from("samply")).chain(args.args); | ||
| let opt = cli::Opt::parse_from(argv); | ||
|
|
||
| // samply spins up its own tokio runtime internally, so it must run on a | ||
|
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. fixup with previous commit |
||
| // thread that isn't already inside our `#[tokio::main]` runtime. | ||
| std::thread::scope(|s| { | ||
| s.spawn(|| match opt.action { | ||
| #[cfg(any( | ||
| target_os = "android", | ||
| target_os = "macos", | ||
| target_os = "linux", | ||
| target_os = "windows" | ||
| ))] | ||
| cli::Action::Record(a) => ::samply::do_record_action(a), | ||
| _ => unimplemented!("Only `samply record` is supported"), | ||
| }) | ||
| .join() | ||
| .map_err(|_| anyhow::anyhow!("samply thread panicked")) | ||
| })?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,16 +152,34 @@ pub enum UnwindingMode { | |
|
|
||
| #[derive(Args, Debug, Clone)] | ||
| pub struct PerfRunArgs { | ||
|
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. this should be renamed and the unwinding mode argument should be scoped to perf, could be done using a generic to avoid having to handle this at runtime |
||
| /// Enable the linux perf profiler to collect granular performance data. | ||
| /// Enable a profiler to collect granular performance data. | ||
| /// This is only supported on Linux. | ||
| #[arg(long, env = "CODSPEED_PERF_ENABLED", default_value_t = true)] | ||
| pub enable_perf: bool, | ||
| #[arg(long, env = "CODSPEED_PROFILER_ENABLED", default_value_t = true)] | ||
| pub enable_profiler: bool, | ||
|
|
||
| /// Deprecated alias for --enable-profiler / CODSPEED_PROFILER_ENABLED. | ||
| #[arg(long, env = "CODSPEED_PERF_ENABLED", hide = true)] | ||
| pub enable_perf: Option<bool>, | ||
|
|
||
| /// The unwinding mode that should be used with perf to collect the call stack. | ||
| #[arg(long, env = "CODSPEED_PERF_UNWINDING_MODE")] | ||
| pub perf_unwinding_mode: Option<UnwindingMode>, | ||
| } | ||
|
|
||
| impl PerfRunArgs { | ||
| /// Resolves the effective `enable_profiler` value, honoring the deprecated | ||
| /// `--enable-perf` / `CODSPEED_PERF_ENABLED` flag with a warning. | ||
| pub fn resolve_enable_profiler(&self) -> bool { | ||
| let Some(legacy) = self.enable_perf else { | ||
| return self.enable_profiler; | ||
| }; | ||
| log::warn!( | ||
| "CODSPEED_PERF_ENABLED / --enable-perf is deprecated; use CODSPEED_PROFILER_ENABLED / --enable-profiler instead." | ||
| ); | ||
| legacy | ||
| } | ||
| } | ||
|
|
||
| /// Parser for go-runner version that validates semver format | ||
| fn parse_version(s: &str) -> Result<semver::Version, String> { | ||
| semver::Version::parse(s).map_err(|e| format!("Invalid semantic version: {e}")) | ||
|
|
||
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.
Can we segregate these subcommands into a dedicated enum so we now at glance which commands are real entrypoints by users and which are actually just the cli re-invoking itself?