Wsl 常见问题记录
1. WSL 上 perf 使用
需要自己编译特定版本的内核 perf
- 确定内核版本
❯ uname -a
Linux Esoye 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- 下载对应内核源码,可以直接 clone,也可以直接下载源码包
https://github.com/microsoft/WSL2-Linux-Kernel.git
- 安装依赖,否则编译的 perf 功能不全,也可以自己研究具体需要那些功能
sudo apt install \
binutils-dev debuginfod libbabeltrace-dev libcap-dev \
libdw-dev libdwarf-dev libelf-dev liblzma-dev libnuma-dev libperl-dev \
libslang2-dev libssl-dev libtraceevent-dev libunwind-dev libzstd-dev libzstd1 python3-dev systemtap-sdt-dev zlib1g-dev
-- 可以按下面提示安装对应版本的依赖
Makefile.config:423: No libelf found. Disables 'probe' tool, jvmti and BPF support in 'perf record'. Please install libelf-dev, libelf-devel or elfutils-libelf-devel
Makefile.config:596: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev
Makefile.config:680: Disabling post unwind, no support found.
Makefile.config:746: No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev
Makefile.config:762: slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev
Makefile.config:809: Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev
Makefile.config:891: Old version of libbfd/binutils things like PE executable profiling will not be available
Makefile.config:940: No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev
Makefile.config:953: No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR
Makefile.config:964: No libcap found, disables capability support, please install libcap-devel/libcap-dev
Makefile.config:977: No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev
Makefile.config:1036: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev
- 编译 perf
cd WSL2-Linux-Kernel-linux-msft-wsl-5.15.153.1/tools/perf
make
- 这里我的版本如下:
* WSL2
* windows11
* Ubuntu24.04
* 5.15.153.1
* gcc 版本 13.2.0
有编译错误,映像中是 gcc 高版本默认编译选项跟严格了,具体忘记了,但是简单修改下源码即可
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Build b/tools/perf/scripts/perl/Perf-Trace-Util/Build
index db00361..d4fd0d4 100644
--- a/tools/perf/scripts/perl/Perf-Trace-Util/Build
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Build
@@ -2,4 +2,4 @@ perf-y += Context.o
CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes
CFLAGS_Context.o += -Wno-unused-parameter -Wno-nested-externs -Wno-undef
-CFLAGS_Context.o += -Wno-switch-default -Wno-shadow
+CFLAGS_Context.o += -Wno-switch-default -Wno-shadow -Wno-declaration-after-statement -Wno-bad-function-cast -Wno-switch-enum
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 803ca42..a59ed44 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -101,3 +101,4 @@ endif
CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
+CFLAGS_bpf.o += -Wno-nonnull
\ No newline at end of file
diff --git a/tools/perf/util/scripting-engines/Build b/tools/perf/util/scripting-engines/Build
index 7b342ce..271f52a 100644
--- a/tools/perf/util/scripting-engines/Build
+++ b/tools/perf/util/scripting-engines/Build
@@ -1,6 +1,6 @@
perf-$(CONFIG_LIBPERL) += trace-event-perl.o
perf-$(CONFIG_LIBPYTHON) += trace-event-python.o
-CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-nested-externs -Wno-undef -Wno-switch-default
+CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-nested-externs -Wno-undef -Wno-switch-default -Wno-declaration-after-statement -Wno-bad-function-cast -Wno-switch-enum
-CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow
+CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-deprecated-declarations
sudo cp perf /usr/bin
验证
❯ perf -v
perf version 5.15.153.1
2. zsk powerlevel10k
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
ZSH_THEME="powerlevel10k/powerlevel10k"
p10k configure
3. docker
sudo apt install docker.io
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json": dial unix /var/run/docker.sock: connect: permission denied
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将当前用户添加到docker用户组
newgrp docker #更新docker用户组
-- 可能可用的镜像,一个一个试
docker pull registry.docker-cn.com/library/ubuntu:22.04
docker pull hub-mirror.c.163.com/library/ubuntu:22.04
docker pull docker.mirrors.ustc.edu.cn/library/ubuntu:22.04
docker pull yxzrazem.mirror.aliyuncs.com/library/ubuntu:22.04
docker pull docker.kubesre.xyz/library/ubuntu:22.04
docker pull dc.j8.work/library/ubuntu:22.04
docker pull docker.registry.cyou/library/ubuntu:22.04
docker pull docker.hlyun.org/library/ubuntu:22.04
docker pull docker.chenby.cn/library/ubuntu:22.04
docker pull docker.jsdelivr.fyi/library/ubuntu:22.04
docker pull docker-mirrors.mjjman.com/library/ubuntu:22.04
docker pull huecker.io/library/ubuntu:22.04
docker pull dockerhub.timeweb.cloud/library/ubuntu:22.04
docker pull docker-cf.registry.cyou/library/ubuntu:22.04
docker pull dockercf.jsdelivr.fyi/library/ubuntu:22.04
docker pull dockertest.jsdelivr.fyi/library/ubuntu:22.04
docker pull dockerhub.azk8s.cn/library/ubuntu:22.04
docker pull mirror.ccs.tencentyun.com/library/ubuntu:22.04
docker pull registry.cn-hangzhou.aliyuncs.com/library/ubuntu:22.04
docker pull docker.m.daocloud.io/library/ubuntu:22.04
docker pull noohub.ru/library/ubuntu:22.04
docker tag 8a3cdc4d1ad3 ubuntu:22.04
docker rmi docker.jsdelivr.fyi/library/ubuntu:24.04
Read other posts