Skip to content

Commit 96c3ff1

Browse files
bors[bot]matklad
andauthored
Merge #5588
5588: Print errors when failing to create a perf counter r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 5844dd0 + 3e1e622 commit 96c3ff1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/ra_prof/src/stop_watch.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ impl StopWatch {
2323
pub fn start() -> StopWatch {
2424
#[cfg(target_os = "linux")]
2525
let counter = {
26-
let mut counter = perf_event::Builder::new().build().ok();
26+
let mut counter = perf_event::Builder::new()
27+
.build()
28+
.map_err(|err| eprintln!("Failed to create perf counter: {}", err))
29+
.ok();
2730
if let Some(counter) = &mut counter {
28-
let _ = counter.enable();
31+
if let Err(err) = counter.enable() {
32+
eprintln!("Failed to start perf counter: {}", err)
33+
}
2934
}
3035
counter
3136
};
@@ -47,7 +52,9 @@ impl StopWatch {
4752
let time = self.time.elapsed();
4853

4954
#[cfg(target_os = "linux")]
50-
let instructions = self.counter.as_mut().and_then(|it| it.read().ok());
55+
let instructions = self.counter.as_mut().and_then(|it| {
56+
it.read().map_err(|err| eprintln!("Failed to read perf counter: {}", err)).ok()
57+
});
5158
#[cfg(not(target_os = "linux"))]
5259
let instructions = None;
5360

0 commit comments

Comments
 (0)