Unnamed repository; edit this file 'description' to name the repository.
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 <[email protected]>
bors[bot] 2021-11-17
parent 9f1e26c · parent 445280a · commit bf408ef
-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 43b1ce9e6d..6258328482 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 {