From d68c2bfda825795483b48ef7ca10c03e296e7e17 Mon Sep 17 00:00:00 2001 From: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com> Date: Wed, 10 Dec 2025 19:33:10 +0000 Subject: [PATCH] profiler: check paranoia level after trying SwCpuClock In some setups, like running in an EKS cluster, currently there's a false negative where the profiler exits before trying SwCpuClock because it sees that the `perf_event_paranoid` level is set to 2. However, if the binary has been given correct capability (CAP_PERFMON), the paranoia level doesn't really matter. This patch fixes it to only check the paranoia level and error if we fail to run with both Hardware and Software CPU Clock events. Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com> --- samply/src/linux/profiler.rs | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/samply/src/linux/profiler.rs b/samply/src/linux/profiler.rs index 24225c5e0..a34f28a64 100644 --- a/samply/src/linux/profiler.rs +++ b/samply/src/linux/profiler.rs @@ -394,25 +394,6 @@ fn init_profiler( attach_mode, ); - if let Err(error) = &perf { - if error.kind() == std::io::ErrorKind::PermissionDenied { - if let Some(level) = paranoia_level() { - if level > 1 { - eprintln!(); - eprintln!( - "'/proc/sys/kernel/perf_event_paranoid' is currently set to {level}." - ); - eprintln!("In order for samply to work with a non-root user, this level needs"); - eprintln!("to be set to 1 or lower."); - eprintln!("You can execute the following command and then try again:"); - eprintln!(" echo '-1' | sudo tee /proc/sys/kernel/perf_event_paranoid"); - eprintln!(); - std::process::exit(1); - } - } - } - } - let mut perf = match perf { Ok(perf) => perf, Err(_) => { @@ -434,6 +415,25 @@ fn init_profiler( Ok(perf) => perf, // Success! Err(error) => { eprintln!("Failed to start profiling: {error}"); + if error.kind() == std::io::ErrorKind::PermissionDenied { + if let Some(level) = paranoia_level() { + if level > 1 { + eprintln!(); + eprintln!( + "'/proc/sys/kernel/perf_event_paranoid' is currently set to {level}." + ); + eprintln!("In order for samply to work with a non-root user, this level needs"); + eprintln!("to be set to 1 or lower."); + eprintln!( + "You can execute the following command and then try again:" + ); + eprintln!( + " echo '-1' | sudo tee /proc/sys/kernel/perf_event_paranoid" + ); + eprintln!(); + } + } + } std::process::exit(1); } }