about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-11-16 18:44:04 +0000
committerGitHub <noreply@github.com>2021-11-16 18:44:04 +0000
commitbf408ef5fdc5f95464eca620f170462b2e831a87 (patch)
treebde057cc8ba7769c6d0752820e3c75db3535d3f4
parent9f1e26c3f9804eaaf2941feaa140d6f8c6d8c562 (diff)
parent445280a1b1d740f084f39efa3f583980adfe1dfa (diff)
downloadrust-bf408ef5fdc5f95464eca620f170462b2e831a87.tar.gz
rust-bf408ef5fdc5f95464eca620f170462b2e831a87.zip
Merge #10777
10777: internal: Allow disabling perf access via `RA_DISABLE_PERF` r=lnicola a=jonas-schievink

https://github.com/rr-debugger/rr does not support the perf-specific ioctls, so add a way to avoid them.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
-rw-r--r--crates/profile/src/stop_watch.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/crates/profile/src/stop_watch.rs b/crates/profile/src/stop_watch.rs
index 43b1ce9e6da..62583284829 100644
--- a/crates/profile/src/stop_watch.rs
+++ b/crates/profile/src/stop_watch.rs
@@ -23,16 +23,27 @@ impl StopWatch {
     pub fn start() -> StopWatch {
         #[cfg(target_os = "linux")]
         let counter = {
-            let mut counter = perf_event::Builder::new()
-                .build()
-                .map_err(|err| eprintln!("Failed to create perf counter: {}", err))
-                .ok();
-            if let Some(counter) = &mut counter {
-                if let Err(err) = counter.enable() {
-                    eprintln!("Failed to start perf counter: {}", err)
+            // When debugging rust-analyzer using rr, the perf-related syscalls cause it to abort.
+            // We allow disabling perf by setting the env var `RA_DISABLE_PERF`.
+
+            use once_cell::sync::Lazy;
+            static PERF_ENABLED: Lazy<bool> =
+                Lazy::new(|| std::env::var_os("RA_DISABLE_PERF").is_none());
+
+            if *PERF_ENABLED {
+                let mut counter = perf_event::Builder::new()
+                    .build()
+                    .map_err(|err| eprintln!("Failed to create perf counter: {}", err))
+                    .ok();
+                if let Some(counter) = &mut counter {
+                    if let Err(err) = counter.enable() {
+                        eprintln!("Failed to start perf counter: {}", err)
+                    }
                 }
+                counter
+            } else {
+                None
             }
-            counter
         };
         let time = Instant::now();
         StopWatch {