为什么 perf record 和 annotate 不起作用?

why does perf record and annotate not work?

我很难过,我阅读了 perf 教程并试图做一个超出 "perf stat" 的简单测试。但是 perf record 要么不起作用,要么 perf annotate 显示没有记录样本。 运行 性能

例如(我 运行 sudo 因为没有它我会得到一堆错误,最后我会 post:

sudo perf record -e cycles,instructions,cache-misses -a -c 1 ./FooExe

[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 1.794 MB perf.data (~78393 samples) ]

.

sudo perf report -D -i perf.data |grep RECORD_SAMPLE |wc -l
Failed to open /tmp/perf-23796.map, continuing without symbols
20486

.

sudo perf annotate -d ./FooExe

the perf.data file has no samples! Press any key

就我所知。我试图从源代码为我的系统重建 perf,但这似乎也没有帮助。

我正在使用 Ubuntu 14.04 内核 3.19.0-49-generic。这是在英特尔 i7 I4510U cpu 上。我确保使用 symbols 编译我的程序,但无论我尝试分析哪个应用程序,我都会得到相同的结果。

-- 如果我 运行 没有 sudo :

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.

Cannot read kernel map
Error:
You may not have permission to collect system-wide stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid:
 -1 - Not paranoid at all
  0 - Disallow raw tracepoint access for unpriv
  1 - Disallow cpu events for unpriv
  2 - Disallow kernel profiling for unpriv

我刚试过你的命令。问题是您使用 -a 来分析系统范围内的所有进程,因此它永远不会 运行 ./FooExe。您可以使用 strace -f perf ... ./FooExe 确认这一点,并注意缺少任何 execve 系统调用。还有一个事实,它 returns 立即,即使 FooExe 应该花费几秒钟。

下面是一个忙循环 awk 命令的示例记录示例:

perf record -e cycles,instructions,cache-misses awk 'BEGIN{for(i=0;i<40000000;i++){}}'

现在 perf report 有效。您不需要为 report 命令指定可执行文件,因为 perf.data 只有一个可执行文件的数据。


这与 the ocperf.py wrapper 的工作方式相同,但您可以使用符号名称记录更多 uarch 特定事件的事件(而不是在 -e 中查找代码和数字参数):

$ ocperf.py record -e cycles,cache-misses,uops_dispatched_port.port_0 awk 'BEGIN{for(i=0;i<40000000;i++){}}'
perf record -e cycles,cache-misses,cpu/event=0xa1,umask=0x1,name=uops_dispatched_port_port_0,period=2000003/ awk 'BEGIN{for(i=0;i<40000000;i++){}}'
  (warning lines about kernel symbols)
[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.352 MB perf.data (7819 samples) 
$ ocperf.py report