From 3e1e6227ca525f8631e0bff2215fa3de1b4f4cc1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:27:19 +0200 Subject: Print errors when failing to create a perf counter --- crates/ra_prof/src/stop_watch.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_prof') diff --git a/crates/ra_prof/src/stop_watch.rs b/crates/ra_prof/src/stop_watch.rs index 8b8ec25a5..5e276190e 100644 --- a/crates/ra_prof/src/stop_watch.rs +++ b/crates/ra_prof/src/stop_watch.rs @@ -23,9 +23,14 @@ impl StopWatch { pub fn start() -> StopWatch { #[cfg(target_os = "linux")] let counter = { - let mut counter = perf_event::Builder::new().build().ok(); + 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 { - let _ = counter.enable(); + if let Err(err) = counter.enable() { + eprintln!("Failed to start perf counter: {}", err) + } } counter }; @@ -47,7 +52,9 @@ impl StopWatch { let time = self.time.elapsed(); #[cfg(target_os = "linux")] - let instructions = self.counter.as_mut().and_then(|it| it.read().ok()); + let instructions = self.counter.as_mut().and_then(|it| { + it.read().map_err(|err| eprintln!("Failed to read perf counter: {}", err)).ok() + }); #[cfg(not(target_os = "linux"))] let instructions = None; -- cgit v1.2.3