linux - 性能:软件事件之间的奇怪关系

标签 linux perf

好吧,这真的让我很烦恼。

我正在使用 perf 记录 cpu-clock 事件(软件事件):

$ > perf record -e cpu-clock srun -n 1 ./stream

... perf report 生成的表是空的。

我正在使用 perf 记录 perf 列表中列出的所有可用软件事件:

$ > perf record -e alignment-faults,context-switches,cpu-clock,cpu-migrations,\
dummy,emulation-faults,major-faults,minor-faults,page-faults,task-clock\
srun -n 1 ./stream

...该表为我提供了可用样本的列表:

0 alignment-faults                                   
125 context-switches                                                
255 cpu-clock                                                  
21 cpu-migrations                                                        
0 dummy                                                              
0 emulation-faults                                             
0 major-faults                                                      
128 minor-faults                 
132 page-faults                                                           
254 task-clock 

我可以查看在 cpu-clock 中收集的样本,它为我提供了信息。为什么?!如果我只测量 cpu-clock,为什么它不起作用?为什么在四个事件中没有收集到样本?

这是这个问题的后续: error: perf.data file has no samples

最佳答案

可能 srun 不使用直接 fork 启动目标进程。它可能会使用一些变体或远程 shell,如 ssh 或守护进程来启动进程。

perf record(没有 -a 选项)将只跟踪直接 fork 的子进程,而不是 sshd 或其他守护进程启动( fork )的进程。如果 srun 可以访问它并且使用了 perf record ... srun 命令,它将永远不会分析远程机器(这是为了分析 srun 应用程序及其派生的所有内容) .

首先尝试 perf stat 以获得总的(原始)性能计数器,并将 perf 作为 srun 参数;这是使用远程 shell 或守护进程的工具的正确用法(可能具有 perf 的完整路径):

 srun -n 1 perf stat ./stream
 srun -n 1 /usr/bin/perf stat ./stream

perf stat 将打印目标任务的运行时间。然后选择一些具有高原始计数器的事件(perf record 通常将采样率调整到几 kHz 左右,因此如果有足够的原始事件计数,将生成数千个样本):

 srun -n 1 perf record -e cpu-clock ./stream
 srun -n 1 /usr/bin/perf record -e cpu-clock ./stream

关于linux - 性能:软件事件之间的奇怪关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44677519/

相关文章:

python - 无法在 Ubuntu 上导入 pip 安装的模块

linux - ssh 用户名@主机名到 ssh 主机名

linux - 为什么我必须使用 libtool --mode==execute gdb wireshark 才能调试 wireshark

linux - 如何在 Linux 上启用 ccache

linux - 如何计算进程 id 的执行指令数,包括子进程

linux - Perl 脚本旨在计算总工资,输出仅显示零。

linux - 根据性能计数器将程序分类为计算密集型

linux - 为什么 perf stat 将 "stalled-cycles-backend"显示为 <不支持>?

c - Perf Profiler 报告过度使用 "do_syscall_64"

linux-kernel - linux 的 perf 实用程序如何理解堆栈跟踪?