読者です 読者をやめる 読者になる 読者になる

DELAEMON BLOG

Live as if you were to die tomorrow. Learn as if you were to live forever.

perf on Fedora22

perf: Linux profiling with performance counters
Perf Wiki

インストール

$ sudo dnf isntall perf

てきとうなコードを用意

$ gcc fib.c -o fib

イベント数を取得

$ perf stat ./fib
832040
failed to read counter stalled-cycles-frontend
failed to read counter stalled-cycles-backend

 Performance counter stats for './fib':

         11.102711      task-clock (msec)         #    0.967 CPUs utilized
                 2      context-switches          #    0.180 K/sec
                 0      cpu-migrations            #    0.000 K/sec
                48      page-faults               #    0.004 M/sec
        19,328,246      cycles                    #    1.741 GHz
   <not supported>      stalled-cycles-frontend
   <not supported>      stalled-cycles-backend
        46,303,730      instructions              #    2.40  insns per cycle
         9,527,011      branches                  #  858.080 M/sec
             5,258      branch-misses             #    0.06% of all branches

       0.011485366 seconds time elapsed

解析実行

$ perf record ./fib
832040
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.012 MB perf.data (47 samples) ]

解析ファイルが作られる

$ ls -la
-rw------- 1 dela dela 14944 Feb  6 11:27 perf.data
-rw------- 1 dela dela 47080 Feb  6 11:16 perf.data.old

解析結果を見る

$ perf report

Samples: 68  of event 'cycles', Event count (approx.): 20695033
Overhead  Command  Shared Object      Symbol
  94.16%  fib      fib                [.] fib
   2.22%  fib      [kernel.kallsyms]  [k] _raw_spin_lock
   1.54%  fib      [kernel.kallsyms]  [k] filemap_map_pages
   1.49%  fib      [kernel.kallsyms]  [k] async_page_fault
   0.27%  fib      [kernel.kallsyms]  [k] bad_range
   0.17%  fib      [kernel.kallsyms]  [k] run_timer_softirq
   0.08%  fib      [kernel.kallsyms]  [k] __remove_hrtimer
   0.06%  fib      [kernel.kallsyms]  [k] native_write_msr_safe