LoginSignup
3
2

More than 5 years have passed since last update.

AOSP(Android)ビルドで非推奨ぽくなったccacheをあえて有効化してみる

Last updated at Posted at 2018-09-26

はじめに

AOSP最新環境をビルドし、リファレンスボード:Hikey960で動かす にてAOSP(Android)ビルド環境の構築について紹介しましたが、最新のビルド環境ではexport USE_CCACHE=1を実行してもccacheが効かなくなっていました。

どうやら、有効化は可能であるものの、ccacheのバイナリを自前で用意した上で追加の設定が必要になっています。

build/make/core/ccache.mk
# We no longer provide a ccache prebuilt.
#
# Ours was old, and had a number of issues that triggered non-reproducible
# results and other failures. Newer ccache versions may fix some of those
# issues, but at the large scale of our build servers, we weren't seeing
# significant performance gains from using ccache -- you end up needing very
# good locality and/or very large caches if you're building many different
# configurations.
#
# Local no-change full rebuilds were showing better results, but why not just
# use incremental builds at that point?
#
# So if you still want to use ccache, continue setting USE_CCACHE, but also set
# the CCACHE_EXEC environment variable to the path to your ccache executable.

有効化するのがためらわれるような文言ですが、お試しするだけしてみます。

ccacheセットアップ

新しめのバージョンのccacheなら大丈夫そうな文言もあるので、最新バージョンを用意します。

$ git clone https://github.com/ccache/ccache.git
$ cd ccache
$ git checkout v3.4.3 ★現時点の最新タグ
$ sudo apt install autoconf ★ビルドに必要
...
$ ./autogen.sh
Now run ./configure and make
$ ./configure
...
$ make -j16
$ ccache -M 32G ★1ビルド環境で22GBほど消費します
Set cache size limit to 32.0 GB 

他で使う予定があるならmake installしてしまってもよいかと。

実行結果

ccache無効

比較元としてccacheを使用していない場合のビルド結果を示します。

$ . ./build/envsetup.sh
$ lunch hikey960-userdebug
$ make clean
...
$ time make -j16
...
#### build completed successfully (01:22:42 (hh:mm:ss)) ####
real    82m42.287s
user    1246m25.517s
sys 40m36.128s

ccache有効:初回ビルド

cacheが空の状態でのビルド結果を示します。

$ export USE_CCACHE=1 ★ccacheの有効化(既存の設定)
$ export CCACHE_EXEC=/work/ccache/ccache ★ccacheのパスを指定(新規に追加された設定)
$ . ./build/envsetup.sh
$ lunch hikey960-userdebug
$ make clean
...
$ time make -j16
...
#### build completed successfully (01:27:28 (hh:mm:ss)) ####
real    87m27.378s
user    1302m31.610s
sys 55m22.672s

cache生成のオーバーヘッド分として数%伸びてはいます。

$ /work/ccache/ccache -s
...
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                         42668
cache hit rate                      0.00 %
called for link                      152
called for preprocessing              26
ccache internal error                282
unsupported code directive             2
cleanups performed                     0
files in cache                    128214
cache size                          22.2 GB
max cache size                      48.0 GB

ビルド1回で22.2GBほどcacheが生成されました。
ビルド環境含めてストレージ食いまくります。。。

ccache有効:2回目ビルド

cacheが生成後の状態でのビルド結果を示します。

$ export USE_CCACHE=1
$ export CCACHE_EXEC=/work/ccache/ccache
$ . ./build/envsetup.sh
$ lunch hikey960-userdebug
$ make clean
...
$ time make -j16
...
#### build completed successfully (27:39 (mm:ss)) ####
real    27m38.993s
user    385m55.988s
sys 14m38.354s

ビルド時間が1/3になりました。
これは効果アリと言ってよいかと思います。

$ /work/ccache/ccache -s
...
cache hit (direct)                 42166
cache hit (preprocessed)             784
cache miss                         42668
cache hit rate                     50.16 %
called for link                      304
called for preprocessing              52
ccache internal error                282
unsupported code directive             4
cleanups performed                     0
files in cache                    128876
cache size                          22.2 GB
max cache size                      32.0 GB

cacheが有効に使われたようです。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2