Ubuntu 18.04中安装perf工具(复制/粘帐/回车 版)

准备使用perf工具分析代码的性能,发现perf安装的方式有好几种。

安装信赖

1.安装flex

flex如果不安装,后面在编译的时候,会出现信赖报错。
报错的内容类似以下:

Warning: Kernel ABI header at 'tools/include/uapi/drm/i915_drm.h' differs from latest version at 'include/uapi/drm/i915_drm.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/kvm.h' differs from latest version at 'include/uapi/linux/kvm.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/prctl.h' differs from latest version at 'include/uapi/linux/prctl.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/disabled-features.h' differs from latest version at 'arch/x86/include/asm/disabled-features.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/uapi/asm/kvm.h' differs from latest version at 'arch/x86/include/uapi/asm/kvm.h'
Warning: Kernel ABI header at 'tools/arch/powerpc/include/uapi/asm/kvm.h' differs from latest version at 'arch/powerpc/include/uapi/asm/kvm.h'
Warning: Kernel ABI header at 'tools/arch/s390/include/uapi/asm/kvm.h' differs from latest version at 'arch/s390/include/uapi/asm/kvm.h'
Makefile.config:137: *** Error: flex is missing on this system, please install it.  Stop.
Makefile.perf:203: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
Makefile:69: recipe for target 'all' failed
make: *** [all] Error 2

flex安装命令:

sudo apt-get install flex
2.安装bison

bison如果没有安装,会报以下错误。

  BUILD:   Doing 'make -j4' parallel build
Warning: Kernel ABI header at 'tools/include/uapi/drm/i915_drm.h' differs from latest version at 'include/uapi/drm/i915_drm.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/kvm.h' differs from latest version at 'include/uapi/linux/kvm.h'
Warning: Kernel ABI header at 'tools/include/uapi/linux/prctl.h' differs from latest version at 'include/uapi/linux/prctl.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/disabled-features.h' differs from latest version at 'arch/x86/include/asm/disabled-features.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
Warning: Kernel ABI header at 'tools/arch/x86/include/uapi/asm/kvm.h' differs from latest version at 'arch/x86/include/uapi/asm/kvm.h'
Warning: Kernel ABI header at 'tools/arch/powerpc/include/uapi/asm/kvm.h' differs from latest version at 'arch/powerpc/include/uapi/asm/kvm.h'
Warning: Kernel ABI header at 'tools/arch/s390/include/uapi/asm/kvm.h' differs from latest version at 'arch/s390/include/uapi/asm/kvm.h'
Makefile.config:141: *** Error: bison is missing on this system, please install it.  Stop.
Makefile.perf:203: recipe for target 'sub-make' failed
make[1]: *** [sub-make] Error 2
Makefile:69: recipe for target 'all' failed
make: *** [all] Error 2

安装命令如下:

sudo apt install bison

pref安装-linux-source

执行以下命令安装linux-source, 包比较大,差不多127M.

sudo apt-get install linux-source

执行完上面命令后,进入/usr/src目录。

cd /usr/src

在这个目录中存在以下文件(参考)。

:/usr/src$ ls
linux-headers-5.3.0-45          linux-headers-5.3.0-46-generic
linux-headers-5.3.0-45-generic  linux-source-4.15.0
linux-headers-5.3.0-46          linux-source-4.15.0.tar.bz2

执行解压命令。

sudo tar -xvjf linux-source-4.15.0.tar.bz2

解压完成后。进入这个目录中的。

cd linux-source-4.15.0/tools/perf

编译安装

在目录perf中,我们执行编译/安装命令。

make && make install

如果提示权限错误,则使用sudo。

sudo make
sudo make install

安装完成后,会在当前目录生成perf的执行文件。接下来,让这个文件全局可用。

sudo ln -s `pwd`/perf /usr/local/bin/perf

验证安装

在系统任意的目录执行:

perf --version

如果版本信息输出,则说明安装已成功。

$ perf --version
perf version 4.15.18

你可能感兴趣的:(nodejs,ubuntu,linux)