WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Unable to use perf on WSL2 Ubuntu 20.04

Open JeffR1992 opened this issue 2 years ago • 4 comments

Windows Version

Microsoft Windows [Version 10.0.22631.2506]

WSL Version

1.2.5.0

Are you using WSL 1 or WSL 2?

  • [X] WSL 2
  • [ ] WSL 1

Kernel Version

5.15.90.1

Distro Version

Ubuntu 20.04

Other Software

perf

Repro Steps

In terminal, run perf -v

Expected Behavior

Information regarding the version of perf available on my system should be returned.

Actual Behavior

I get the following error:

WARNING: perf not found for kernel 5.15.90.1-microsoft

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

  You may also want to install one of the following packages to keep up to date:
    linux-tools-standard-WSL2
    linux-cloud-tools-standard-WSL2

Diagnostic Logs

I installed perf using sudo apt install linux-tools-generic, and can see that it was installed to /usr/lib/linux-tools/5.4.0-166-generic/perf (although it seems to be the wrong version for my kernel).

I've also tried running sudo apt install linux-tools-5.15.90.1-microsoft-standard-WSL2 and sudo apt install linux-tools-standard-WSL2, as directed by the warning mentioned above, but get the following errors:

E: Unable to locate package linux-tools-5.15.90.1-microsoft-standard-WSL2
E: Couldn't find any package by glob 'linux-tools-5.15.90.1-microsoft-standard-WSL2'

and

E: Unable to locate package linux-tools-standard-WSL2

respectively.

JeffR1992 avatar Nov 09 '23 21:11 JeffR1992

It looks like when I run the command perf -v, it tries to run the perf binary in /usr/bin/perf instead of /usr/lib/linux-tools/5.4.0-166-generic/perf. If I cd /usr/lib/linux-tools/5.4.0-166-generic/ and run ./perf -v, then I get the following:

perf version 5.4.252

So it looks like I can use the linux-tools version of perf, but not the /usr/bin version. But the OS by default points to the /usr/bin version even after the linux-tools version is installed. Is this the expected behavior or would this still be regarded as a bug?

JeffR1992 avatar Nov 10 '23 01:11 JeffR1992

Any updates on this? One of the reasons I was so excited that WSL2 came out was finally the ability to use such tooling on Windows. But it seems that it's unsupported?

Update: Adding the specific linux-tools path to PATH seem to do the trick. Shame that this doesn't work out of the box. However unsure if this a WSL2 issue or an Ubuntu packaging issue?

lypanov avatar Nov 02 '24 18:11 lypanov

Still an issue

$ perf --version
WARNING: perf not found for kernel 5.15.167.4-microsoft
                                                                                                                                              
You may need to install the following packages for this specific kernel:
    linux-tools-5.15.167.4-microsoft-standard-WSL2
    linux-cloud-tools-5.15.167.4-microsoft-standard-WSL2

  You may also want to install one of the following packages to keep up to date:
    linux-tools-standard-WSL2
    linux-cloud-tools-standard-WSL2

It would be great if the kernel used by WSL2 was following the expectations set for Ubuntu kernel packages. But I guess we would have better luck asking Ubuntu for a linux-tools generic packages that would be used as default when kernel and per kernel linux-tools doesn't match.

ydroneaud avatar May 19 '25 09:05 ydroneaud

struggling with this today just trying to get an apples-to-apples benchmark (wall clock time doesn't cut it since different computers operate at different speeds), could it be possible to fix this or provide a workaround?

bionicles avatar Jun 15 '25 22:06 bionicles

There are some instructions on how to do this here: https://gist.github.com/abel0b/b1881e41b9e1c4b16d84e5e083c38a13

However initially when I ran the commands the build was failing because of warning messages and warnings as errors is on by default so I got it to build by doing make -j$(nproc) WERROR=0

rchriste avatar Dec 08 '25 05:12 rchriste