Perf 工具移植使用出现的问题

本文详细记录了Perf性能分析工具在深度裁剪内核中的移植与使用过程,包括正确的编译方法、必要的内核配置选项以及常见问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Perf 工具移植使用出现的问题

最近公司开发新项目,对性能做优化,选择工具Perf,由于内核经过了深度裁剪,Perf功能不可用,该问记录Perf的功能开启调试过程,遇到的问题做整理,日常笔记记录:
1、Perf工具移植,(网络文献移植存在问题,不建议参考)。
正确方法,在对应内核源码中有tools文件夹,直接可以编译想要的工具

make clean

make CROSS_COMPILE=aarch64-linux- ARCH=arm64 perf

只对交叉编译器和架构做指定即可,如果想添加插件那要先移植插件了,此处不做赘述。

2、内核配置(先做内核配置,后做工具编译)
配置依据 http://www.brendangregg.com/perf.html

for perf_events: CONFIG_PERF_EVENTS=y

for stack traces: CONFIG_FRAME_POINTER=y

kernel symbols: CONFIG_KALLSYMS=y

tracepoints: CONFIG_TRACEPOINTS=y

kernel function trace: CONFIG_FTRACE=y

kernel-level dynamic tracing: CONFIG_KPROBES=y CONFIG_KPROBE_EVENTS=y

user-level dynamic tracing: CONFIG_UPROBES=y CONFIG_UPROBE_EVENTS=y

full kernel debug info: CONFIG_DEBUG_INFO=y

kernel lock tracing: CONFIG_LOCKDEP=y

kernel lock tracing: CONFIG_LOCK_STAT=y

kernel dynamic tracepoint variables: CONFIG_DEBUG_INFO=y

注:前3个配置完成即可使用,内核重新配置编译后,工具重新编译

3、Perf工具运行
1)perf top 问题:如下错误

[root@rk3399:/]# perf top
Cannot read kernel map
perf_event_open(…, PERF_FLAG_FD_CLOEXEC) failed with unexpected error 38 (Function not implemented)
perf_event_open(…, 0) failed unexpectedly with error 38 (Function not implemented)
Error:
The sys_perf_event_open() syscall returned with 38 (Function not implemented) for event (cycles).
/bin/dmesg may provide additional information.
No CONFIG_PERF_EVENTS=y kernel support configured?

问题解决:
1、

perf_event_open(…, PERF_FLAG_FD_CLOEXEC) failed with unexpected error 38 (Function not implemented) perf_event_open(…, 0) failed
unexpectedly with error 38 (Function not implemented) Error: The
sys_perf_event_open() syscall returned with 38 (Function not
implemented) for event (cycles). /bin/dmesg may provide additional
information.

这部分问题是perf工具移植错误,按照网上的方法不可行。
请参考本文1中移植方法进行编译。

2、

Cannot read kernel map
Segmentation fault

问题解决:
如果有该问题发生,是由于内核配置项 “装载所有的调试符号表信息” 未勾选。

CONFIG_KALLSYMS=y

2)perf stat -a 问题:

[root@rk3399:/]# perf stat -a
^C
Performance counter stats for ‘system wide’:
not supported> task-clock
not supported> context-switches
not supported> cpu-migrations
not supported> page-faults
not supported> cycles
not supported> stalled-cycles-frontend
not supported> stalled-cycles-backend
not supported> instructions
not supported> branches
not supported> branch-misses
1.382871584 seconds time elapsed

问题解决:
这部分问题是perf工具移植错误,按照网上的方法不可行。
请参考本文1中移植方法进行编译。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值