Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially missed stack trace #337

Open
dima74 opened this issue Sep 3, 2024 · 5 comments
Open

Partially missed stack trace #337

dima74 opened this issue Sep 3, 2024 · 5 comments

Comments

@dima74
Copy link

dima74 commented Sep 3, 2024

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:

image

Approximately half of the fibonacci calls have correct stacktrace, however other half doesn't have stacktrace

@djc
Copy link
Contributor

djc commented Sep 4, 2024

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.

@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
@dima74
Copy link
Author

dima74 commented Sep 4, 2024

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

image

With cargo flamegraph:

cargo build --example fib && flamegraph -o flamegraph2.svg -- ./target/debug/examples/fib

image


When using cargo flamegraph, there are 9% [unknown] samples, when using perf directly there are no [unknown] samples

@djc djc reopened this Sep 4, 2024
@mstange
Copy link
Contributor

mstange commented Sep 4, 2024

The difference is probably the passing of -g rather than --call-graph dwarf. So maybe the issue is caused by perf's dwarf unwinding.

@dima74
Copy link
Author

dima74 commented Sep 13, 2024

Maybe add info to the README that cargo flamegraph uses --call-graph dwarf and example how to use -g instead

@djc
Copy link
Contributor

djc commented Sep 13, 2024

Happy to review a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants