天天看點

WSL安裝 perf工具

WSL中安裝perf工具時,按照一般安裝方法,安裝linux-tools-common後,執行perf工具提示

WARNING: perf not found for kernel 4.4.0-18362

You may need to install the following packages for this specific

kernel:

linux-tools-4.4.0-18362-Microsoft

linux-cloud-tools-4.4.0-18362-Microsoft

You may also want to install one of the following packages to keep up

to date:

linux-tools-Microsoft

linux-cloud-tools-Microsoft

然而以上安裝包在apt-get中找不到,是以重新使用源碼編譯的方法安裝perf

首先安裝編譯工具

sudo apt install build-essential flex bison libssl-dev libelf-dev
           

然後下載下傳WSL源碼

git clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.git
           

github下載下傳如果比較慢,gitee有鏡像源

git clone https://gitee.com/mirrors/WSL2-Linux-Kernel.git
           

下載下傳完成後,進行編譯

cd WSL2-Linux-Kernel/tools/perf
make
           

編譯成功後,即可在此檔案夾下找到perf工具,執行成功,也可以自行将perf工具移動到/usr/bin檔案夾下友善調用

[email protected]:/mnt/d/code$ perf

 usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

 The most commonly used perf commands are:
   annotate        Read perf.data (created by perf record) and display annotated code
   archive         Create archive with object files with build-ids found in perf.data file
   bench           General framework for benchmark suites
   buildid-cache   Manage build-id cache.
   buildid-list    List the buildids in a perf.data file
   c2c             Shared Data C2C/HITM Analyzer.
   config          Get and set variables in a configuration file.
   data            Data file related processing
   diff            Read perf.data files and display the differential profile
   evlist          List the event names in a perf.data file
   ftrace          simple wrapper for kernel's ftrace functionality
   inject          Filter to augment the events stream with additional information
   kallsyms        Searches running kernel for symbols
   kmem            Tool to trace/measure kernel memory properties
   kvm             Tool to trace/measure kvm guest os
   list            List all symbolic event types
   lock            Analyze lock events
   mem             Profile memory accesses
   record          Run a command and record its profile into perf.data
   report          Read perf.data (created by perf record) and display the profile
   sched           Tool to trace/measure scheduler properties (latencies)
   script          Read perf.data (created by perf record) and display trace output
   stat            Run a command and gather performance counter statistics
   test            Runs sanity tests.
   timechart       Tool to visualize total system behavior during a workload
   top             System profiling tool.
   probe           Define new dynamic tracepoints
   trace           strace inspired tool

 See 'perf help COMMAND' for more information on a specific command.

           

參考:https://stackoverflow.com/questions/60237123/is-there-any-method-to-run-perf-under-wsl

繼續閱讀