ARM64版本的Ubuntu上安装perf

作者: zhaorenhai

perf是linux下一个很好用的性能分析,性能调优工具。在x86版本的Ubuntu上面,使用perf时,如果默认没有安装,会提示你apt install linux-tools-common,然后再安装apt install linux-tools-x.x.x-generic linux-cloud-tools-x.x.x-generic 一般就可以正常使用了。
但是当前ARM64版本的Ubuntu上面还不支持这么直接安装perf。 接下来我们就介绍下如何在ARM64版本的Ubuntu上安装perf

首先查看系统是否已经安装了linux源码

1
cd /usr/src

查看是否有linux-source-x.x.x 目录,如果没有,要先安装linux源码,

1
apt install linux-source

安装完毕之后,一般安装的格式是一个bz2包,还要先解压:

1
tar -jxf linux-source-x.x.x.tar.bz2

另外编译perf需要flex,先安装一下flex

1
apt install flex

然后进入如下目录:

1
cd linux-source-x.x.x/tools/perf

直接执行make,这是第一遍make,即使make成功了,也会提示很多包没安装,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Auto-detecting system features:
... dwarf: [ OFF ]
... dwarf_getlocations: [ OFF ]
... glibc: [ on ]
... gtk2: [ OFF ]
... libaudit: [ OFF ]
... libbfd: [ OFF ]
... libcap: [ OFF ]
... libelf: [ OFF ]
... libnuma: [ on ]
... numa_num_possible_cpus: [ on ]
... libperl: [ OFF ]
... libpython: [ OFF ]
... libcrypto: [ on ]
... libunwind: [ OFF ]
... libdw-dwarf-unwind: [ OFF ]
... zlib: [ on ]
... lzma: [ OFF ]
... get_cpuid: [ OFF ]
... bpf: [ on ]
... libaio: [ on ]
... libzstd: [ OFF ]
... disassembler-four-args: [ OFF ]

Makefile.config:369: 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:506: No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev
Makefile.config:581: Disabling post unwind, no support found.
Makefile.config:662: slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev
Makefile.config:679: GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev
Makefile.config:706: Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev
Makefile.config:733: No python interpreter was found: disables Python support - please install python-devel/python-dev
Makefile.config:829: No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev
Makefile.config:842: No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR
Makefile.config:853: No libcap found, disables capability support, please install libcap-devel/libcap-dev
Makefile.config:921: No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev

根据上面的提示,把需要装的包,用apt install命令都安装了,
然后

1
make clean

再执行一遍

1
make

如果还有提示某些包没装,建议尽量还是装一下,不然perf的某些功能可能就不正常,重复上面这三个步骤:make clean,装包,make,直到输出的提示里的包,你确定不装对你需要的功能没有影响,就可以了。
最后再

1
make install

这时,perf目录下应该会生成一个perf可执行文件。
然后再执行一下如下命令,就可以正常使用perf了

1
ln -s  /usr/src/linux-source-x.x.x/tools/perf/perf /usr/local/bin/perf

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×