diff --git a/src/executor/helpers/env.rs b/src/executor/helpers/env.rs index 8970ddf4..ee4d6cf0 100644 --- a/src/executor/helpers/env.rs +++ b/src/executor/helpers/env.rs @@ -50,6 +50,14 @@ pub fn get_base_injected_env( env } +/// Set the env variable to not warn users about Go's perf unwinding mode when running Go benchmarks +pub fn suppress_go_perf_unwinding_warning() { + // Safety: no multithreading + unsafe { + std::env::set_var("CODSPEED_GO_SUPPRESS_PERF_UNWINDING_MODE_WARNING", "true"); + } +} + pub fn is_codspeed_debug_enabled() -> bool { std::env::var("CODSPEED_LOG") .ok() diff --git a/src/executor/helpers/introspected_golang/go.sh b/src/executor/helpers/introspected_golang/go.sh index 10f4ce55..6aba393d 100755 --- a/src/executor/helpers/introspected_golang/go.sh +++ b/src/executor/helpers/introspected_golang/go.sh @@ -32,6 +32,11 @@ if [ $# -eq 0 ]; then exit $? fi +# On arm64, warn about setting CODSPEED_PERF_UNWINDING_MODE to "fp" for correct flamegraphs +if [ "$(uname -m)" = "aarch64" ] && [ "${CODSPEED_GO_SUPPRESS_PERF_UNWINDING_MODE_WARNING:-}" != "true" ]; then + echo "::warning::Go profiling on arm64 require frame pointer unwinding. Set CODSPEED_PERF_UNWINDING_MODE=fp for better profiling." >&2 +fi + # Route command based on first argument case "$1" in test) diff --git a/src/executor/wall_time/perf/mod.rs b/src/executor/wall_time/perf/mod.rs index bfbfc9aa..a6d3df41 100644 --- a/src/executor/wall_time/perf/mod.rs +++ b/src/executor/wall_time/perf/mod.rs @@ -4,6 +4,7 @@ use crate::cli::UnwindingMode; use crate::executor::ExecutorConfig; use crate::executor::helpers::command::CommandBuilder; use crate::executor::helpers::env::is_codspeed_debug_enabled; +use crate::executor::helpers::env::suppress_go_perf_unwinding_warning; use crate::executor::helpers::harvest_perf_maps_for_pids::harvest_perf_maps_for_pids; use crate::executor::helpers::run_command_with_log_pipe::run_command_with_log_pipe_and_callback; use crate::executor::helpers::run_with_sudo::run_with_sudo; @@ -98,6 +99,8 @@ impl PerfRunner { (mode, None) } else if config.command.contains("cargo") { (UnwindingMode::Dwarf, None) + } else if config.command.contains("go test") { + (UnwindingMode::FramePointer, None) } else if config.command.contains("pytest") || config.command.contains("uv") || config.command.contains("python") @@ -112,7 +115,10 @@ impl PerfRunner { }; let cg_mode = match cg_mode { - UnwindingMode::FramePointer => "fp", + UnwindingMode::FramePointer => { + suppress_go_perf_unwinding_warning(); + "fp" + } UnwindingMode::Dwarf => &format!("dwarf,{}", stack_size.unwrap_or(8192)), }; debug!("Using call graph mode: {cg_mode:?}");