Is there any method to run perf under WSL?
WARNING: perf not found for kernel 4.19.84-microsoft
Because WSL2 uses custom Linux kernel. Its source code can be found here microsoft/WSL2-Linux-Kernel. We have to compile perf tools from it.
Procedure
- Install required build packages. If you are using Ubuntu in WSL2 this is the required command:
sudo apt install build-essential flex bison libssl-dev libelf-dev
- Clone the WSL2 Linux kernel repository:
git clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git
- Go to perf folder and compile it:
cd WSL2-Linux-Kernel/tools/perf
make
perf
executable file will be in that folder.
You can install linux-tools-generic
.
apt install linux-tools-generic
Then run perf
using the install path /usr/lib/linux-tools/<linux-version>-generic/perf
.
Some tools, like flamegraph
, will use environment variable PERF
as the perf
path.
PERF=/usr/lib/linux-tools/<linux-version>-generic/perf flamegraph -- my_program