Partially missed stack trace
Consider simple Rust program calculating fibonacci number:
fn main() {
println!("{}", fibonacci(42));
}
fn fibonacci(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
Here is result of cargo flamegraph:
Approximately half of the fibonacci calls have correct stacktrace, however other half doesn't have stacktrace
This is more due to the underlying profiling backend (perf if you're on Linux), not flamegraph itself. You might be able to increase the profiling frequency to capture a larger percentage of stack traces, at the expense of slower runtime.
I don't observe such behaviour when using perf directly with the same frequence as cargo flamegraph uses by default.
With perf:
cargo build --example fib && perf record -F 997 -g -- ./target/debug/examples/fib && perf script | stackcollapse-perf.pl | flamegraph.pl >flamegraph1.svg
With cargo flamegraph:
cargo build --example fib && flamegraph -o flamegraph2.svg -- ./target/debug/examples/fib
When using cargo flamegraph, there are 9% [unknown] samples, when using perf directly there are no [unknown] samples
The difference is probably the passing of -g rather than --call-graph dwarf. So maybe the issue is caused by perf's dwarf unwinding.
Maybe add info to the README that cargo flamegraph uses --call-graph dwarf and example how to use -g instead
Happy to review a PR.