Open Kixiron opened 4 years ago
perf
doesn't work with WSL1. It should work with WSL2 though.
Alright, would you like me to keep the issue open until WSL2 releases in the next few months?
I am not a maintainer of flamegraph
.
WSL2 still has problems running:
~/source/repos/flamegraph master target/release/flamegraph ls
Cargo.lock LICENSE-APACHE README.md example.svg flamegraph.svg perf.data.old target
Cargo.toml LICENSE-MIT bors.toml example_cropped.png perf.data src
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.008 MB perf.data ]
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" })', /home/mborejszo/source/repos/flamegraph/src/lib.rs:265:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
This is more of a WSL issue though, as perf
seems to be lacking some important info from hypervisor (not 100% sure atm if this is due to what Hyper-V presents to guest, or to my specific hardware setup):
List of pre-defined events (to be used in -e):
alignment-faults [Software event]
bpf-output [Software event]
context-switches OR cs [Software event]
cpu-clock [Software event]
cpu-migrations OR migrations [Software event]
dummy [Software event]
emulation-faults [Software event]
major-faults [Software event]
minor-faults [Software event]
page-faults OR faults [Software event]
task-clock [Software event]
msr/tsc/ [Kernel PMU event]
rNNN [Raw hardware event descriptor]
cpu/t1=v1[,t2=v2,t3 ...]/modifier [Raw hardware event descriptor]
(see 'man perf-list' on how to encode it)
mem:<addr>[/len][:access] [Hardware breakpoint]
~/source/repos/flamegraph master ● perf stat ls
Cargo.lock LICENSE-APACHE README.md example.svg flamegraph.svg perf.data.old target
Cargo.toml LICENSE-MIT bors.toml example_cropped.png perf.data src
Performance counter stats for 'ls':
0.41 msec task-clock:u # 0.782 CPUs utilized
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
110 page-faults:u # 0.000 K/sec
<not supported> cycles:u
<not supported> instructions:u
<not supported> branches:u
<not supported> branch-misses:u
0.000519900 seconds time elapsed
0.000560000 seconds user
0.000000000 seconds sys
NOTE: to be able to use perf
at all in WSL2, you first need to compile it - see https://stackoverflow.com/a/60276918
This used to work on my old machine with WSL2, but on my new computer it's been broken. Hmm.
I had/am having somewhat similar issues trying to use flamegraph in WSL 2. I was able to install perf
just fine and it does seem to work generally but it does have some missing functionality as mentioned here - https://github.com/microsoft/WSL/issues/8480 (cycles, instructions, etc. is "not supported").
I've tried running both:
cargo flamegraph -c "record -e instructions -c 100 --call-graph lbr -g" -- --pattern Napoleon --file-path war_and_peace.txt --context 0
and
cargo flamegraph -- --pattern Napoleon --file-path war_and_peace.txt --context 0
The key to making it work was running:
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
Before trying to run flamegraph
I am still working on getting it to work with my Criterion benchmarks, getting "no bench target named" errors but the above was setup (perf install and configuration)
Not sure if this was an update or its working for some reason randomly, but my perf is showing the extra stats that it didn't before I updated WSL and in general my profiling tools are working/better. So probably update WSL if it isn't already.
Performance counter stats for 'ls':
0.91 msec task-clock:u # 0.414 CPUs utilized
0 context-switches:u # 0.000 /sec
0 cpu-migrations:u # 0.000 /sec
108 page-faults:u # 118.877 K/sec
799088 cycles:u # 0.880 GHz
67771 stalled-cycles-frontend:u # 8.48% frontend cycles idle
190109 stalled-cycles-backend:u # 23.79% backend cycles idle
584112 instructions:u # 0.73 insn per cycle
# 0.33 stalled cycles per insn
122569 branches:u # 134.914 M/sec
8289 branch-misses:u # 6.76% of all branches
0.002195808 seconds time elapsed
0.002259000 seconds user
0.000000000 seconds sys
Attempting to run
cargo flamegraph
yields the following error (Note: #81 also manifests, possibly due to something related to workspacing)Rust Version:
System info: