Perf for WSL2

2021-08-31 10:56:14 浏览数 (1)

WSL2 has better support for native Linux development, and Vscode can work with it well. But it doesn't provide the `perf' command, which is used intensively. The post in stackoverflow provides several solutions. One solution is to build `perf' from the source code. And it is the most reliable way to keep the `perf' command matching the Linux kernel.

The steps are listed as follows,

  1. Clone the kernel source code for WSL2 Linux
代码语言:txt复制
```
代码语言:txt复制
$ git clone https://github.com/microsoft/WSL2-Linux-Kernel
代码语言:txt复制
```
  1. Kernel version must match `uname -a`, find the correct tag.
代码语言:txt复制
<https://github.com/microsoft/WSL2-Linux-Kernel/tags>
  1. Get latest tags and check it out
代码语言:txt复制
<https://devconnected.com/how-to-checkout-git-tags/>
代码语言:txt复制
```
代码语言:txt复制
$ git fetch --all --tags
代码语言:txt复制
$ git checkout tags/<tag> -b <branch>
代码语言:txt复制
```
  1. Build (make sure to install the missing packages)
代码语言:txt复制
```
代码语言:txt复制
$ cd WSL2-Linux-Kernel/tools/perf
代码语言:txt复制
$ make
代码语言:txt复制
<snipped>
代码语言:txt复制
Makefile.config:600: slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev
代码语言:txt复制
Makefile.config:614: GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev
代码语言:txt复制
<snipped>
代码语言:txt复制
```
代码语言:txt复制
Hold breath. Pay attention to the error messages and install the missing packages. For example, If TUI is not enabled, "perf top -g" will not have the expandable " " sign. Without this functionality, perf (top|report) -g's output is ugly and not readable. If there are any warnings saying the include files' mismatch, make sure to sync the kernel include files with the tools include files. Copying files from $topdir/include/xxx to tools/include/xxx may not work, see <https://github.com/bombela/backward-cpp/pull/165/files> for a concrete example on errors in srcline.c.

If everything is OK, you can run the perf command under tools/ directory or copy it to /usr/bin/perf.

links to: https://zedware.github.io

0 人点赞