20.2. perf stat を使用したイベントのカウント
perf stat
を使用すると、コマンドの実行中に発生したハードウェアおよびソフトウェアのイベントをカウントし、これらのカウントの統計を生成できます。デフォルトでは、perf stat
はスレッドごとのモードで動作します。
前提条件
-
perf のインストール で説明されているように、
perf
ユーザー領域ツールがインストールされている。
手順
イベントをカウントします。
root アクセスなしで
perf stat
コマンドを実行すると、ユーザー空間で発生したイベントのみをカウントします。$ perf stat ls
例20.1 perf stat の出力が root アクセスなしで実行
Desktop Documents Downloads Music Pictures Public Templates Videos Performance counter stats for 'ls': 1.28 msec task-clock:u # 0.165 CPUs utilized 0 context-switches:u # 0.000 M/sec 0 cpu-migrations:u # 0.000 K/sec 104 page-faults:u # 0.081 M/sec 1,054,302 cycles:u # 0.823 GHz 1,136,989 instructions:u # 1.08 insn per cycle 228,531 branches:u # 178.447 M/sec 11,331 branch-misses:u # 4.96% of all branches 0.007754312 seconds time elapsed 0.000000000 seconds user 0.007717000 seconds sys
以前の例で分かるように、
perf stat
を root アクセスなしで実行すると、イベント名の後に:u
が付けられ、これらのイベントがユーザー空間でのみカウントされていることが分かります。ユーザー空間およびカーネルスペースの両方のイベントをカウントするには、
perf stat
の実行時に root アクセスが必要になります。# perf stat ls
例20.2 root アクセスで実行された perf stat の出力
Desktop Documents Downloads Music Pictures Public Templates Videos Performance counter stats for 'ls': 3.09 msec task-clock # 0.119 CPUs utilized 18 context-switches # 0.006 M/sec 3 cpu-migrations # 0.969 K/sec 108 page-faults # 0.035 M/sec 6,576,004 cycles # 2.125 GHz 5,694,223 instructions # 0.87 insn per cycle 1,092,372 branches # 352.960 M/sec 31,515 branch-misses # 2.89% of all branches 0.026020043 seconds time elapsed 0.000000000 seconds user 0.014061000 seconds sys
デフォルトでは、
perf stat
はスレッドごとのモードで動作します。CPU 全体のイベントカウントに変更するには、-a
オプションをperf stat
に渡します。CPU 全体のイベントをカウントするには、root アクセスが必要です。# perf stat -a ls
関連情報
-
システム上の
perf-stat(1)
man ページ