wsl 上安装 perf
参考使用 bcc:https://massoudasadiblog.blogspot.com/2024/07/ebpf-on-wsl2-kernel-version-6x-ubuntu.html?m=1 参考:https://gist.github.com/abel0b/b1881e41b9e1c4b16d84e5e083c38a13
- https://gist.github.com/MarioHewardt/5759641727aae880b29c8f715ba4d30f 参考bcc的安装文档:https://github.com/iovisor/bcc/blob/master/INSTALL.md#wslwindows-subsystem-for-linux—binary
bcc的安装可以参考这个:http://www.aisoftcloud.cn/blog/article/1684117709501802?session=
下面是我本地的 wsl2 版本,安装的是 Ubuntu 22.04
PS C:\Users\muclo> wsl --version
WSL 版本: 2.3.26.0
内核版本: 5.15.167.4-1
WSLg 版本: 1.0.65
MSRDC 版本: 1.2.5620
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.26100.1-240331-1435.ge-release
Windows 版本: 10.0.26100.2605
通过以下命令来安装 perf
wsl --update # 查看自己的内核是否需要更新
sudo apt update
sudo apt install flex bison
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
- 在执行
make -j8
的时候,会发现本地缺少的包是什么,根据提示来依次安装后,再重新执行make
,如下所示: ```bash Makefile.config:471: No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR Makefile.config:476: No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev Makefile.config:597: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev Makefile.config:645: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR Makefile.config:688: Disabling post unwind, no support found. Makefile.config:768: slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev Makefile.config:815: Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev Makefile.config:965: No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev Makefile.config:978: No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR Makefile.config:989: No libcap found, disables capability support, please install libcap-devel/libcap-dev Makefile.config:1002: No numa.h found, disables ‘perf bench numa mem’ benchmark, please install numactl-devel/libnuma-devel/libnuma-dev Makefile.config:1061: No libbabeltrace found, disables ‘perf data’ CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev Makefile.config:1095: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
Auto-detecting system features: … dwarf: [ OFF ] … dwarf_getlocations: [ OFF ] … glibc: [ on ] … libbfd: [ OFF ] … libbfd-buildid: [ OFF ] … libcap: [ OFF ] … libelf: [ on ] … libnuma: [ OFF ] … numa_num_possible_cpus: [ OFF ] … libperl: [ OFF ] … libpython: [ on ] … libcrypto: [ on ] … libunwind: [ OFF ] … libdw-dwarf-unwind: [ OFF ] … zlib: [ on ] … lzma: [ OFF ] … get_cpuid: [ on ] … bpf: [ on ] … libaio: [ on ] … libzstd: [ OFF ]
一个不完全的清单可能如下,具体的根据上述提示来安装:
```bash
sudo apt install python-dev-is-python3 libtraceevent-dev libcap-dev \
binutils-dev libnuma-dev libunwind-dev libdw-dev libslang2-dev systemtap-sdt-dev liblzma-dev libzstd-dev libbabeltrace-dev
注意事项:
- 在使用
make -j8
编译的时候,需要注意你现在的环境,如果处于 conda 环境下,那么使用的 python 版本也会是 conda 下的,因此可能会找不到对应的 libpythonxx.so 文件。 - 需要使用
conda deactivate
退出虚拟环境后才能使用本地下的环境进行安装# conda 常用命令 conda-env list # 查看已有虚拟环境 which python # 看使用的 python 是哪里的 conda create -n test_env python=3.10 # 使用 python3.10 创建 test_enc 环境 conda remove -n test_env --all # 删除虚拟环境 conda activate test_env # 激活环境,进不去的话可以尝试 source activate test_env