18.2. 통계로 이벤트 계산

perf stat 를 사용하여 명령 실행 중에 하드웨어 및 소프트웨어 이벤트 발생을 계산하고 이러한 개수의 통계를 생성할 수 있습니다. 기본적으로 perf stat 는 스레드별 모드에서 작동합니다.

사전 요구 사항

  • perf 설치에 설명된 대로 perf 사용자 공간 도구가 설치되어 있습니다.

절차

  • 이벤트를 계산합니다.

    • 루트 액세스 권한 없이 perf stat 명령을 실행하면 사용자 영역에서만 발생하는 이벤트 수입니다.

      $ perf stat ls

      예 18.1. 루트 액세스없이 실행되었던 perf stat의 출력

      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 가 뒤따르면 이러한 이벤트가 사용자 공간에만 계산되었음을 나타냅니다.

    • 사용자 공간 및 커널 공간 이벤트를 모두 계산하려면 stat 를 실행할 때 root 액세스 권한이 있어야 합니다.

      # perf stat ls

      예 18.2. 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) 도움말 페이지