7回复
2年前
一个Linux中 单独用户空间/内核空间中的 Perf 指令/周期计数问题
在用 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
ps:
1,ls 在这里只是作为一个例子来突出这个问题。
2,运行的是 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]
那应该如何解决此问题?是我哪里做错了什么吗?
856 阅读