はじめに
大量のソースコードを build する場合、build 時間が長時間になることがしばしばです。
ccacheを使うことで、2度目以降の build 時間を短縮することができます。
ここでは ccacheの使い方を説明します。 OS は Ubuntu 14.04 です。
install
apt-getを使ってinstallします。version は 3.1.9 です。
console
$ sudo apt-get install -y ccache
$ ccache --version
ccache version 3.1.9
setup
PATHを設定します。.bashrc に追記しておきます。
console
$ export PATH=/usr/lib/ccache:$PATH
$ echo -e "\nexport PATH=/usr/lib/ccache:\$PATH" >> $HOME/.bashrc
sample
build する ソースコード を取得します。
なんでもいいのですが、ここでは busybox を download します。
https://busybox.net/downloads/
console
$ tar jxvf busybox-1.26.2.tar.bz2
$ cd busybox-1.26.2
$ make defconfig
$ time make -j4
real 2m44.376s
user 4m5.563s
sys 0m53.794s
2m44sかかりました。
make clean 後 再度 build します。
console
$ make clean
$ time make -j4
real 1m18.415s
user 1m35.769s
sys 0m33.424s
1m18になりました。 build 時間が 半分になりました。
cache 情報
-s オプションでcacheの情報を見れます。
console
$ ccache -s
cache directory /home/user/.ccache
cache hit (direct) 4
cache hit (preprocessed) 516
cache miss 526
called for link 37
called for preprocessing 7
no input file 174
files in cache 2133
cache size 16.6 Mbytes
max cache size 1.0 Gbytes
cacheの実体はデフォルトで$HOME/.ccacheに置かれます。
console
$ ls /home/user/.ccache
0 1 2 3 4 5 6 7 8 9 CACHEDIR.TAG a b c d e f tmp
cache data の 最大値 は -M option で指定します。
console
$ ccache -M 2G
Set cache size limit to 2.0 Gbytes
$ ccache -s
(...)
max cache size 2.0 Gbytes