本文基于Ubuntu18.04
系统,介绍Linux性能分析工具perf
的安装方法。
输入perf
命令,提示:
root@ubuntu:/home/run# perf Command 'perf' not found, but can be installed with: apt install linux-tools-common
安装linux-tools-common
:
root@ubuntu:/home/run# apt-get install linux-tools-common Reading package lists... Done Building dependency tree Reading state information... Done linux-tools-common is already the newest version (4.15.0-147.151). The following packages were automatically installed and are no longer required: linux-hwe-5.4-headers-5.4.0-72 linux-hwe-5.4-headers-5.4.0-73 Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 250 not upgraded. root@ubuntu:/home/run# perf WARNING: perf not found for kernel 5.4.0-77 You may need to install the following packages for this specific kernel: linux-tools-5.4.0-77-generic linux-cloud-tools-5.4.0-77-generic You may also want to install one of the following packages to keep up to date: linux-tools-generic linux-cloud-tools-generic
注:先安装linux-tools-5.4.0-77-generic
时,会报错。
因此,先安装了下面的两条命令:
root@ubuntu:/home/run# apt-get install linux-tools-generic linux-cloud-tools-generic Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-hwe-5.4-headers-5.4.0-72 linux-hwe-5.4-headers-5.4.0-73 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: linux-cloud-tools-4.15.0-147 linux-cloud-tools-4.15.0-147-generic linux-cloud-tools-common linux-tools-4.15.0-147 linux-tools-4.15.0-147-generic The following NEW packages will be installed: linux-cloud-tools-4.15.0-147 linux-cloud-tools-4.15.0-147-generic linux-cloud-tools-common linux-cloud-tools-generic linux-tools-4.15.0-147 linux-tools-4.15.0-147-generic linux-tools-generic 0 upgraded, 7 newly installed, 0 to remove and 250 not upgraded. Need to get 4,831 kB of archives. After this operation, 24.4 MB of additional disk space will be used. Do you want to continue? [Y/n] y
继续安装命令:
root@ubuntu:/home/run# apt-get install linux-tools-5.4.0-77-generic Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-hwe-5.4-headers-5.4.0-72 linux-hwe-5.4-headers-5.4.0-73 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: linux-hwe-5.4-tools-5.4.0-77 linux-hwe-5.4-tools-common The following NEW packages will be installed: linux-hwe-5.4-tools-5.4.0-77 linux-hwe-5.4-tools-common linux-tools-5.4.0-77-generic 0 upgraded, 3 newly installed, 0 to remove and 250 not upgraded. Need to get 5,337 kB of archives. After this operation, 25.2 MB of additional disk space will be used. Do you want to continue? [Y/n] y
和
root@ubuntu:/home/run# apt-get install linux-cloud-tools-5.4.0-77-generic Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-hwe-5.4-headers-5.4.0-72 linux-hwe-5.4-headers-5.4.0-73 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: linux-hwe-5.4-cloud-tools-5.4.0-77 linux-hwe-5.4-cloud-tools-common The following NEW packages will be installed: linux-cloud-tools-5.4.0-77-generic linux-hwe-5.4-cloud-tools-5.4.0-77 linux-hwe-5.4-cloud-tools-common 0 upgraded, 3 newly installed, 0 to remove and 250 not upgraded. Need to get 187 kB of archives. After this operation, 1,959 kB of additional disk space will be used. Do you want to continue? [Y/n]
执行perf命令:
root@ubuntu:/home/run# 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. version display the version of perf binary probe Define new dynamic tracepoints trace strace inspired tool
{{o.name}}
{{m.name}}