操作系统:Ubuntu 18.04 问题:如何分析多进程程序?
我通常使用 GNU perf 工具对程序进行如下分析:
perf stat -d ./main [args]
,该命令将返回详细的性能计数器,如下所示:
47,455.09 msec task-clock # 8.602 CPUs utilized
129,199 context-switches # 0.003 M/sec
92 cpu-migrations # 0.002 K/sec
16,228 page-faults # 0.342 K/sec
117,757,409,457 cycles # 2.481 GHz (49.84%)
236,496,093,412 instructions # 2.01 insn per cycle (62.31%)
1,454,901,353 branches # 30.658 M/sec (62.18%)
6,168,091 branch-misses # 0.42% of all branches (62.30%)
183,462,410,176 L1-dcache-loads # 3866.021 M/sec (62.55%)
189,736,991 L1-dcache-load-misses # 0.10% of all L1-dcache hits (62.75%)
8,330,520 LLC-loads # 0.176 M/sec (50.14%)
628,142 LLC-load-misses # 7.54% of all LL-cache hits (50.25%)
5.516529249 seconds time elapsed
46.947476000 seconds user
0.989185000 seconds sys
我关注的是 CPU 效率(第 1 行)、IPC(第 6 行)、L1 和 LLC 带宽(第 9 和 11 行)。
但是现在,我需要分析一个 MPI 程序的每个进程,假设我们有 3 个进程通过执行mpiexec -np 3 ./main [args]
,我怎样才能分别获得每个进程的 CPU 效率、IPC、L1 和 LLC 信息?(通过使用 perf stat -d,我只能得到包含 3 个进程的整体信息,这对我来说目前还不够)
我想要的输出是这样的:
PID: 1
LLC Band.: xxx
PID: 2
LLC Band.: xxx
PID: 3
LLC Band.: xxx
我怎样才能做到这一点?(我想知道 GNU 能gperf
做到这一点吗?或者有一些 C++ 方法可以做到这一点吗?)