gperf linux 安装_perf 安装及使用

环境:ubuntu16.04

1.在terminal输入如下命令,安装与当前内核版本一致的工具

sudo apt-get install linux-tools-common

sudo apt-get install linux-tools-"$(uname -r)"

sudo apt-get install linux-cloud-tools-"$(uname -r)"

sudo apt-get install linux-tools-generic

sudo apt-get install linux-cloud-tools-generic

安装完成后,terminal输入perf,可以显示perf的用法介绍。

2.一般环境中,安装完成后,使用perf top/perf record是不能正常工作的:

WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,

check /proc/sys/kernel/kptr_restrict.

Samples in kernel functions may not be resolved if a suitable vmlinux

file is not found in the buildid cache or in the vmlinux path.

Samples in kernel modules won't be resolved at all.

If some relocation was applied (e.g. kexec) symbols may be misresolved

even with a suitable vmlinux or kallsyms file.

perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 13 (Permission denied)

perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)

Error:

You may not have permission to collect stats.

Consider tweaking /proc/sys/kernel/perf_event_paranoid,

which controls use of the performance events system by

unprivileged users (without CAP_SYS_ADMIN).

The current value is 3:

-1: Allow use of (almost) all events by all users

Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK

>= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN

Disallow raw tracepoint access by users without CAP_SYS_ADMIN

>= 1: Disallow CPU event access by users without CAP_SYS_ADMIN

>= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN

To make this setting permanent, edit /etc/sysctl.conf too, e.g.:

kernel.perf_event_paranoid = -1

两种解决方法:

(1)使用sudo权限,如sudo perf top。

(2)设置kenel.perf_event_paranoid:

(2.1)临时设置,需要sudo su切换到root用户后再进行如下操作,操作完成后返回原用户,此时输入perf top可以正常工作。该方法系统重启后失效。

如果是ubuntu16.04系统:

echo 0 > /proc/sys/kernel/kptr_restrict

echo -1 > /proc/sys/kernel/perf_event_paranoid

如果是ubuntu18.04系统(未实测):

echo -1 > /proc/sys/kernel/perf_event_paranoid

(2.2)修改配置文件,重启后仍有效。

编辑/etc/sysctl.conf,在文件末尾加上:

kernel.kptr_restrict=0  (如果是ubuntu16.04则加入该配置)

kernel.perf_event_paranoid= -1

最后,使用sysctl -p /etc/sysctl.conf命令reload配置文件。

参考:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值