How to use Linux perf tool on WSL2? How to have perf for the correct kernel?
Asked Answered
S

1

8

I am trying to use the perf tool of Linux on my WSL2 using Windows10 machine. I have done every step of the accepted answer here:Is there any method to run perf under WSL?

When I ran "make" comment, I got a warning:

Warning: Kernel ABI header at 'tools/include/uapi/linux/stat.h' differs from latest version at 'include/uapi/linux/stat.h'

But the perf executable was still created. However when I try to use perf like this:

sudo perf record -g myexe myargs

I received this error:

WARNING: perf not found for kernel 5.10.16.3-microsoft

You may need to install the following packages for this specific kernel: linux-tools-5.10.16.3-microsoft-standard-WSL2 linux-cloud-tools-5.10.16.3-microsoft-standard-WSL2

Then I tried to run this:

sudo apt install linux-tools-5.10.16.3-microsoft-standard-WSL2

However that did not work either, I got this:

Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package linux-tools-5.10.16.3-microsoft-standard-WSL2 E: Couldn't find any package by glob 'linux-tools-5.10.16.3-microsoft-standard-WSL2'

What should I do now?

Slattern answered 30/11, 2021 at 20:5 Comment(7)
Are you sure you have WSL2? Apparently it can be non-obvious whether a WSL install is actually WSL2 or WSL1: Does WSL 2 really support 32 bit program?Leprose
@PeterCordes hello! yes i am pretty sure, because it says version is 2 when I run the command "wsl --list --verbose".Slattern
On Debian 11 ("Bullseye") under WSL2, the perf_5.10 command installed by the "linux-perf-5.10" package as a dependency of the "linux-perf" package seems to work.Caroleecarolin
perf looks at CPU hardware counters which will all return 0 in a VM.Eduino
@Eduino but i specifically researched to learn that perf works on WSL2Slattern
Have you succeeded with perf under WSL2?Emprise
Seems the only way is to build perf yourself. Not so hard per the instructions here: #60237623Ephraim
T
0

Just run your newly built perf instead of the /usr/bin/perf which is a shell script to invoke real kernel-specific perf.

I usually replace the /usr/bin/perf with my own perf.

$ sudo ln -sf $(pwd)/perf /usr/bin/perf
Tousle answered 28/3 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.