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中移植方法进行编译。