【发布时间】:2021-12-02 23:44:06
【问题描述】:
我正在尝试使用 perf 分析具有用户空间和内核空间代码的应用程序。我尝试了启用各种内核配置的所有其他可能性,但我无法获得仅在用户空间/内核空间中的指令/周期数。我尝试使用 ":u" 和 ":k 对指令和周期计数的扩展,但我得到的只是答复
$ perf stat -e cycles:u,instructions:u ls
Performance counter stats for 'ls':
<not supported> cycles:u
<not supported> instructions:u
0.006047045 seconds time elapsed
0.000000000 seconds user
0.008098000 seconds sys
但是,仅针对循环/指令运行会产生如下所示的正确结果。
$ perf stat -e cycles,instructions ls
Performance counter stats for 'ls':
5362086 cycles
528783 instructions # 0.10 insn per cycle
0.005487940 seconds time elapsed
0.007800000 seconds user
0.000000000 seconds sys
注意:这里 ls 只是作为一个例子来强调问题。
我正在运行 Linux 5.4 和 perf 版本 5.4.77.g1206eede9156。而且,我正在 ARM 板上运行上述命令。以下是我在 Linux 内核中启用的配置
CONFIG_PERF_EVENTS=y
CONFIG_PROFILING=y
CONFIG_TRACEPOINTS=y
CONFIG_KPROBES=y
CONFIG_OPTPROBES=y
CONFIG_KPROBES_ON_FTRACE=y
CONFIG_UPROBES=y
CONFIG_HAVE_KPROBES=y
CONFIG_HAVE_KRETPROBES=y
CONFIG_HAVE_OPTPROBES=y
CONFIG_HAVE_KPROBES_ON_FTRACE=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_DWARF4=y
CONFIG_FRAME_POINTER=y
CONFIG_FTRACE=y
CONFIG_KPROBE_EVENTS=y
CONFIG_UPROBE_EVENTS=y
CONFIG_PROBE_EVENTS=y
此外,命令行上的 perf list 列出了硬件/软件事件等等
$ perf list
branch-instructions OR branches [Hardware event]
branch-misses [Hardware event]
cache-misses [Hardware event]
cache-references [Hardware event]
cpu-cycles OR cycles [Hardware event]
instructions [Hardware event]
alignment-faults [Software event]
bpf-output [Software event]
context-switches OR cs [Software event]
cpu-clock [Software event]
cpu-migrations OR migrations [Software event]
dummy [Software event]
emulation-faults [Software event]
major-faults [Software event]
minor-faults [Software event]
page-faults OR faults [Software event]
task-clock [Software event]
duration_time [Tool event]
L1-dcache-load-misses [Hardware cache event]
L1-dcache-loads [Hardware cache event]
L1-dcache-prefetch-misses [Hardware cache event]
L1-dcache-prefetches [Hardware cache event]
L1-dcache-store-misses [Hardware cache event]
L1-dcache-stores [Hardware cache event]
L1-icache-load-misses [Hardware cache event]
L1-icache-loads [Hardware cache event]
L1-icache-prefetch-misses [Hardware cache event]
L1-icache-prefetches [Hardware cache event]
branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]
dTLB-load-misses [Hardware cache event]
dTLB-store-misses [Hardware cache event]
iTLB-load-misses [Hardware cache event]
请建议如何解决此问题。我做错了什么吗?
【问题讨论】:
标签: linux linux-kernel profiling performancecounter perf