Skip to content

Commit 90fd5fc

Browse files
d-e-s-oanakryiko
authored andcommitted
rust/examples/profile: Handle errors more gracefully
It is entirely possible for symbolization to fail for legitimate reasons when profiling the system continuously. For example, a process could terminate between the time addresses from it were captured and we attempt to symbolize them, in which case an error will be reported by blazesym. As it stands such an error will shoot down the profiler, which is not the desired behavior. With this change we handle such errors more gracefully by just printing an error message. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent b87dbf2 commit 90fd5fc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

examples/rust/profile/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ fn show_stack_trace(stack: &[u64], symbolizer: &symbolize::Symbolizer, pid: u32)
8989
symbolize::Source::from(symbolize::Process::new(pid.into()))
9090
};
9191

92-
let syms = symbolizer.symbolize(&src, stack).unwrap();
92+
let syms = match symbolizer.symbolize(&src, stack) {
93+
Ok(syms) => syms,
94+
Err(err) => {
95+
eprintln!(" failed to symbolize addresses: {err:#}");
96+
return
97+
},
98+
};
99+
93100
for i in 0..stack.len() {
94101
if syms.len() <= i || syms[i].len() == 0 {
95102
println!(" {} [<{:016x}>]", i, stack[i]);

0 commit comments

Comments
 (0)