perfコマンドをソースからビルドする

linuxカーネルの計測ツールであるperfコマンドをソースからビルドしました。必要なライブラリを揃えるのにけっこう苦労したのでメモを残します。

linux 3.16.1
debian jessie armel

準備

$ sudo apt-get install \
 flex bison python pkg-config libaudit-dev binutils-dev \
 libelf-dev python-dev libpython-dev libperl-dev \
 libslang2-dev libdw-dev libiberty-dev 

armelにはlibunwind7-dev と libnuma-dev は無いので省きました。
また、GUIは使用しないのでgtkも入れませんでした。

ビルド

armのマシン上に、linux v3.16.1 のソースコードを展開して

$ cd tools/perf
$ make
  BUILD:   Doing 'make -j2' parallel build
config/Makefile:350: No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
config/Makefile:426: GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev
config/Makefile:585: No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev

Auto-detecting system features:
...                         dwarf: [ on  ]
...                         glibc: [ on  ]
...                          gtk2: [ OFF ]
...                      libaudit: [ on  ]
...                        libbfd: [ on  ]
...                        libelf: [ on  ]
...                       libnuma: [ OFF ]
...                       libperl: [ on  ]
...                     libpython: [ on  ]
...                      libslang: [ on  ]
...                     libunwind: [ OFF ]
...            libdw-dwarf-unwind: [ on  ]
...     DWARF post unwind library: libdw

  GEN      common-cmds.h
  ...
  (snip)
  ...

ライブラリが足りなくてauto detectがうまくいかないときは、config/feature-checks/ の下の検出用プログラムが何かビルドエラーになっていると思うので、そのディレクトリで単独でmakeすると何かわかります。

$ ./perf stat ls
CREDITS                  builtin-diff.o    builtin-record.c     config
Documentation            builtin-evlist.c  builtin-record.o     design.txt
MANIFEST                 builtin-evlist.o  builtin-report.c     lib
  ...(snip) ...
builtin-buildid-list.o   builtin-probe.c   command-list.txt     util
builtin-diff.c           builtin-probe.o   common-cmds.h

 Performance counter stats for 'ls':

          7.812500      task-clock (msec)         #    0.420 CPUs utilized
                28      context-switches          #    0.004 M/sec
                 0      cpu-migrations            #    0.000 K/sec
                78      page-faults               #    0.010 M/sec
           7946598      cycles                    #    1.017 GHz
           1677282      stalled-cycles-frontend   #   21.11% frontend cycles idle
           6520742      stalled-cycles-backend    #   82.06% backend  cycles idle
           2128870      instructions              #    0.27  insns per cycle
                                                  #    3.06  stalled cycles per insn
            233255      branches                  #   29.857 M/sec
             90247      branch-misses             #   38.69% of all branches

       0.018604500 seconds time elapsed