我正在尝试使用perf分析Azure VM(Ubuntu 18.04)内的应用程序。但性能统计并未提供所有统计信息。
Performance counter stats for 'ls':
0.78 msec task-clock # 0.760 CPUs utilized
1 context-switches # 0.001 M/sec
0 cpu-migrations # 0.000 K/sec
106 page-faults # 0.135 M/sec
<not supported> cycles
<not supported> instructions
<not supported> branches
<not supported> branch-misses
0.001031061 seconds time elapsed
0.001016000 seconds user
0.000000000 seconds sys
而且,性能列表
也没有列出任何硬件事件。
List of pre-defined events (to be used in -e):
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]
msr/pperf/ [Kernel PMU event]
msr/smi/ [Kernel PMU event]
msr/tsc/ [Kernel PMU event]
rNNN [Raw hardware event descriptor]
cpu/t1=v1[,t2=v2,t3 ...]/modifier [Raw hardware event descriptor]
我了解到 VM 的 CPU 性能计数器未启用 source .
是否可以在 Azure VM 中启用硬件事件?或者是否有其他方法可以查找执行应用程序时使用的指令?
最佳答案
问题:
is there any other way to find the instructions used while executing an application?
答案:
如果您有时间或者可以调整应用程序以限制仅检查程序的某些部分,那么 valgrind 的 callgrind 工具将为您提供非常准确的数字,以及深入的分析选项(例如,通过 kachegrind 检查调用配置文件);但使用此功能的应用程序通常需要花费 10-20 倍的时间,这可能是一个大问题(perf stat -e instructions
没有做太多事情,如果对所花费的时间有影响的话)。
附带问题:perf
可在本地虚拟机/云虚拟 guest 上使用吗?
确实如此,但并非在所有配置上(如果您无法更改虚拟化设置,就像大多数 Azure 环境的情况一样)[仅当您可以调整 Hyper-V 配置或进行调整时才有效(请如果您找到了一种方法,请发表评论,因为我还没有)],您无法获得性能计数器)。
属于已知设置的是 Qemu、VMWare 等 - 一般来说,您可以检查 the documentation for VMs with RR ,因为该软件也适用于硬件计数器。
关于linux - 如何让 Perf 在 Azure VM 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69375056/