Flamegraph shows every caller is [unknown]?

I'm just starting to use flamegraph, and I can't figure out why it is labeling every item in the graph as "unknown":

flamegraph

I searched all the github issues in flamegraph and inferno, as well as stack exchange. I'm not sure what I'm missing. Here's how I install and run flamegraph for a given rust crate.

sudo apt install -y linux-tools-generic linux-cloud-tools-generic
cargo install flamegraph
echo -1 |sudo tee /proc/sys/kernel/perf_event_paranoid
cargo flamegraph --dev

I'd sure appreciate any suggestions! Thanks!

How are you compiling your code?

It could be that the generated binary doesn't contain debug symbols, so when the profiler takes a sample it can't figure out which function a particular stack frame corresponds to.

An easy way to check is with the nm tool:

$ cat main.rs
  fn main() {
      println!("Hello, World!");
  }
$ rustc -O main.rs

# A normal binary with debug symbols
$ nm main
  00000000000051c0 T main
  0000000000005220 T __rust_alloc
  0000000000005260 T __rust_alloc_error_handler
  0000000000005250 T __rust_alloc_zeroed
  00000000000191b0 T rust_begin_unwind
  ...
  0000000000012dd0 T _ZN98_$LT$std..ffi..os_str..OsString$u20$as$u20$core..borrow..Borrow$LT$std..ffi..os_str..OsStr$GT$$GT$6borrow17h426ce7e9c06d07beE

# Remove the debug symbols
$ strip main
$ nm main
  nm: main: no symbols

If I replace the println!() with a panic!() and set RUST_BACKTRACE=1 the normal version will show a backtrace while the version without debug symbols won't.

$ RUST_BACKTRACE=1 ./main
  thread 'main' panicked at 'Hello, World!', main.rs:2:5
  stack backtrace:
     0: std::panicking::begin_panic
     1: main::main
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

$ strip main
$ RUST_BACKTRACE=1 ./main_stripped
  thread 'main' panicked at 'Hello, World!', main.rs:2:5
  stack backtrace:
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
3 Likes

I did have symbols, but you helped convince me to try again.
I made a hello world project, which showed the same [unknown]s.
It also generated more warnings about non-root permissions.

What I was missing was:

echo 0 |sudo tee /proc/sys/kernel/kptr_restrict

Thanks again, this helped me find the issue.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.