LoginSignup
1
0

WSL2のUbuntuにperfをインストールする

Posted at

問題

WSL2のUbuntuにはperfがインストールされておらず、実行すると以下のような警告が表示されます。

$ perf
WARNING: perf not found for kernel 5.15.133.1-microsoft

  You may need to install the following packages for this specific kernel:
    linux-tools-5.15.133.1-microsoft-standard-WSL2
    linux-cloud-tools-5.15.133.1-microsoft-standard-WSL2

  You may also want to install one of the following packages to keep up to date:
    linux-tools-standard-WSL2
    linux-cloud-tools-standard-WSL2

もっとも、この警告のとおりにパッケージをインストールしようとすると、以下のようなエラーになり、インストールできません。

$ sudo apt-get install linux-tools-standard-WSL2 linux-cloud-tools-standard-WSL2
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
E: パッケージ linux-tools-standard-WSL2 が見つかりません
E: パッケージ linux-cloud-tools-standard-WSL2 が見つかりません

解決策

WSL2のUbuntuにperfコマンドをインストールしたい場合、上記のレポジトリから自前でビルドする必要があります。

# 依存ライブラリのインストール
sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev

# レポジトリのクローン
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1

# 対象ディレクトリへ移動
cd WSL2-Linux-Kernel/tools/perf

# ビルド実行
make -j8

# perfコマンドをコピー
sudo cp perf /usr/local/bin

環境情報

C:\>wsl --version
WSL バージョン: 2.0.14.0
カーネル バージョン: 5.15.133.1-1
WSLg バージョン: 1.0.59
MSRDC バージョン: 1.2.4677
Direct3D バージョン: 1.611.1-81528511
DXCore バージョン: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows バージョン: 10.0.22631.3296
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0