12.2. perf 통계를 사용하여 이벤트 계산
perf stat 을 사용하여 명령 실행 중에 하드웨어 및 소프트웨어 이벤트 발생 횟수를 계산하고 이러한 개수의 통계를 생성할 수 있습니다. 기본적으로 perf stat 은 스레드당 모드에서 작동합니다.
사전 요구 사항
-
perf사용자 공간 도구는 설치 perf 에 설명된 대로 설치됩니다. - 사용자 공간 및 커널 공간 이벤트를 모두 계산할 수 있는 루트 액세스 권한이 있습니다.
프로세스
이벤트를 계산합니다.
root 액세스 권한 없이
perf stat명령을 실행하면 사용자 공간에서 발생하는 이벤트만 계산됩니다.$ perf stat ls 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은 루트 액세스 없이 실행되며 이벤트 이름 뒤에 :u followed by:u, 이러한 이벤트가 사용자 공간에서만 계산되었음을 나타냅니다.사용자 공간 및 커널 공간 이벤트를 모두 계산하려면 다음을 입력합니다.
# perf stat ls 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 전체 이벤트 수로 변경하려면perf stat에-a옵션을 전달합니다. CPU 전체 이벤트를 계산하려면 root 액세스가 필요합니다.# perf stat -a ls