

Install perf on WSL 2
source link: https://gist.github.com/abel0b/b1881e41b9e1c4b16d84e5e083c38a13
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Install perf on WSL 2 · GitHub
Instantly share code, notes, and snippets.
Thank you!
Does perf stat work for people? Think perf counters are disabled? microsoft/WSL#4678
@StephanDollberg, sadly it didn’t work for me in the end since WSL does not support them but this gist still is helpful as it will work once they do support it. I just switched to linux!
Hello, I did that but I have a compilation error when I use 'make' command.
Makefile.config:844: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
CC util/env.o
Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
CC pmu-events/pmu-events.o
CC util/event.o
CC util/evlist.o
CC util/evsel.o
CC util/evsel_fprintf.o
CC util/find_bit.o
CC util/kallsyms.o
util/env.c: In function ‘perf_env__arch’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
util/env.c:166:17: note: declared here
166 | struct utsname uts;
How can I fix this error ? I'm using Ubuntu 18.04, did I need to switch on version 20.04 ? Maybe the problem come from my GCC version ?
Author
Hello, I did that but I have a compilation error when I use 'make' command.
Makefile.config:844: No alternatives command found, you need to set JDIR= to point to the root of your Java directory CC util/env.o Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h' CC pmu-events/pmu-events.o CC util/event.o CC util/evlist.o CC util/evsel.o CC util/evsel_fprintf.o CC util/find_bit.o CC util/kallsyms.o util/env.c: In function ‘perf_env__arch’: cc1: error: function may return address of local variable [-Werror=return-local-addr] util/env.c:166:17: note: declared here 166 | struct utsname uts;
How can I fix this error ? I'm using Ubuntu 18.04, did I need to switch on version 20.04 ? Maybe the problem come from my GCC version ?
I don't know. I used WSL2 with Ubuntu 20.04 which has gcc 9.3 and it worked. You could try with an other compiler.
As pointed by @StephanDollberg, note that most features of perf will not work because WSL doesnt support hardware counters.
I switched to Ubuntu 20.04 and it works perfectly, thanks. I think the problem came from my GCC version that I updated to version 10.
make[1]: *** [Makefile.perf:206: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make[1]: *** [Makefile.perf:206: sub-make] Error 2 make: *** [Makefile:70: all] Error 2
encountering the same error. it seems things had been changed
I'm running into this error:
jvmti/jvmti_agent.c:48:21: error: static declaration of ‘gettid’ follows non-static declaration
48 | static inline pid_t gettid(void)
| ^~~~~~
A search online has me thinking that the perf build may be broken with newer glibc versions: https://lkml.org/lkml/2019/6/13/1409
However, I had luck compiling perf from the linux-msft-wsl-5.10.16.3
branch, which is newer than what's in master
at present:
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1 --branch linux-msft-wsl-5.10.16.3
Thanks, that help me a lot
make[1]: *** [Makefile.perf:206: sub-make] Error 2 make: *** [Makefile:70: all] Error 2
encountering the same error. it seems things had been changed
This is a crlf issue. It can be fixed by running dos2unix over all files, or setting git config --global core.autocrlf input
before checkout.
Thanks for the gist! To actually make sense of the perf record, and get the interactive menu, also install theses on top of flex and bison to let perf demangle binaries :
libdwarf-dev libelf-dev libnuma-dev libpython3-dev libunwind-dev libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev
Just adding to this one. The source code to perf
can also be downloaded from here. The instructions would change a bit:
- Download the tar.gz file for the version you want. Here I picked 5.10.0, so the file is
perf-5.10.0.tar.gz
- Copy the tar file to your target destination (i.e., in
~
) - Run
tar -xvf perf-5.10.0.tar.gz
cd perf-5.10.0/tools/perf
and run the rest of the instructions to build the binary.
@jayg-hive Thank you, this worked for me!
Thanks for the gist! To actually make sense of the perf record, and get the interactive menu, also install theses on top of flex and bison to let perf demangle binaries :谢谢你的要点!要真正理解 perf 记录,并获得交互式菜单,还要在 flex 和 bison 上安装这些文件,让 perf demangle 二进制文件: libdwarf-dev libelf-dev libnuma-dev libpython3-dev libunwind-dev libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev
Thanks, I am using ubuntu 22.04 on WSL 2 with kernel version v5.15.90.1, after installing the following packages, my perf works well:
# windows
wsl --update
# wsl 2
sudo apt update
sudo apt install flex bison
sudo apt install libdwarf-dev libelf-dev libnuma-dev libunwind-dev \
libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev \
systemtap-sdt-dev libssl-dev libperl-dev python-dev-is-python3 \
binutils-dev libiberty-dev libzstd-dev libcap-dev libbabeltrace-dev
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8 # parallel build
sudo cp perf /usr/local/bin
Awesome! Worked great after running this ty :)
windows
wsl --update
sudo apt update
sudo apt install flex bison
sudo apt install libdwarf-dev libelf-dev libnuma-dev libunwind-dev
libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev
systemtap-sdt-dev libssl-dev libperl-dev python-dev-is-python3
binutils-dev libiberty-dev libzstd-dev libcap-dev libbabeltrace-dev
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8 # parallel build
sudo cp perf /usr/local/bin
After fixing CRLF, worked like a charm!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK