flamegraph-rs / flamegraph

Easy flamegraphs for Rust projects and everything else, without Perl or pipes <3
Apache License 2.0
4.61k stars 141 forks source link

unable to generate a flamegraph from the collapsed stack data #62

Open zeeshanlakhani opened 4 years ago

zeeshanlakhani commented 4 years ago

I'm receiving this error error within an ubuntu container running on a VM (Virtualbox) atop MacOS Mojave (via multiple runs on 0.1.13 and the current git/master version):

cargo flamegraph --bin=skeleton -- --file=skeleton.toml

Then everything runs as expected, but then:

...
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.119 MB perf.data (8 samples) ]
writing flamegraph to "flamegraph.svg"
thread 'main' panicked at 'unable to generate a flamegraph from the collapsed stack data: Io(Custom { kind: InvalidData, error: "No stack counts found" })', src/libcore/result.rs:1165:5

Seemingly related to https://github.com/ferrous-systems/flamegraph/issues/16, but this is now within a container on a VM instead.

Thanks.

spacejam commented 4 years ago

I wonder if using the new -c flag for manually specifying perf arguments could help you here, assuming perf works at all on the VM?

Maybe try different callgraph modes: fp (most likely to work), dwarf (default), and lbr (least likely to work) substituted for the below argument to --call-graph

cargo flamegraph -c "record -e instructions -c 100 --call-graph lbr -g"
cloutiertyler commented 2 years ago

@spacejam I'm getting this same issue in Docker. Tried your suggested -c flag, but I got:

Error:
The instructions event is not supported.
failed to sample program

Removing that and trying fp alas did not help. Thanks for the suggestion though!

duckfromdiscord commented 1 year ago

still happening. no fix for this yet?

writing flamegraph to "flamegraph.svg"
Error: unable to generate a flamegraph from the collapsed stack data

Caused by:
    0: I/O error: No stack counts found
    1: No stack counts found
duckfromdiscord commented 1 year ago

this is on windows

djc commented 1 year ago

@nico-abram any tips?

nico-abram commented 1 year ago

I just ran a quick test on windows on the tip of flamegraph's main branch. Seems to work via blondie on a simple test binary.

@duckfromdiscord Are you running flamegraph as admin? Do you have dtrace installed? Are you on windows 10? If so, could you share which version? (I recall running into a specific version which was a bit buggy in https://github.com/flamegraph-rs/flamegraph/pull/202#issuecomment-1129575600 )

If you have dtrace installed, flamegraph is using that to generate callstacks. You could try running dtrace manually with something like this:

dtrace "-x" "ustackframes=100" "-n" 'profile-997 /pid == $target/ { @[ustack(100)] = count(); }' "-o" "cargo-flamegraph.stacks" "-c" "path/to/your/binary"

dtrace on windows has a bug tracker here: https://github.com/microsoft/DTrace-on-Windows/issues

If you're running as admin and don't have dtrace, it's trying to use a library I wrote last year, I don't have a good guess as to what's happening . A test project would be useful.

duckfromdiscord commented 1 year ago

@nico-abram to answer your questions:

ahmtcn123 commented 1 year ago

Same here with dtrace windows

djc commented 1 year ago

@ahmtcn123 see above, did you try with blondie?

ahmtcn123 commented 1 year ago

@djc Sorry for replying so late, Yes it works well with blondie.

miguno commented 1 year ago

I am running into the same (?) issue as the original poster, in my case on bare-metal macOS 13.4 (M1).

$ cargo flamegraph --root
dtrace: system integrity protection is on, some features will not be available

dtrace: description 'profile-997 ' matched 1 probe
Hello, world! # <<< test output of my binary
dtrace: pid 59523 has exited
writing flamegraph to "flamegraph.svg"
Error: unable to generate a flamegraph from the collapsed stack data

Caused by:
    0: I/O error: No stack counts found
    1: No stack counts found

The flamegraph is successfully generated sometimes, but in only like 2 out of 10 attempts.

djc commented 1 year ago

On macOS, maybe try https://github.com/mstange/samply instead of flamegraph. IME the dtrace backend has never worked very well.

miguno commented 1 year ago

Thanks for this tip, @djc. Samply seems to work better on macOS.