'ccache' configuration

2019-08-12 03:41发布

I have a question related to ccache configuration. In our development environment we have hundreds of make files that build objects using absolute paths.

I wanted to speed up the process and use ccache. Unfortunately when compiling from different locations I can see cache misses. Below is an example of simplified situation where source files are placed in different directories. How do I have to setup ccache to get the proper hit ratio?

I tried to play with setting the CCACHE_BASEDIR variable with no success:

developer@crunchbang:~$ pwd
/home/developer
developer@crunchbang:~$ ccache -s
cache directory                     /home/developer/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
files in cache                         0
cache size                             0 Kbytes
max cache size                       1.0 Gbytes
developer@crunchbang:~$ ccache g++ -c /home/developer/unique_name1/contest.cpp
developer@crunchbang:~$ ccache g++ -c /home/developer/unique_name2/contest.cpp
developer@crunchbang:~$ ccache -s
cache directory                     /home/developer/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             2
files in cache                         4
cache size                            16 Kbytes
max cache size                       1.0 Gbytes
developer@crunchbang:~$ ccache g++ -c /home/developer/unique_name1/contest.cpp
developer@crunchbang:~$ ccache g++ -c /home/developer/unique_name2/contest.cpp
developer@crunchbang:~$ ccache -s
cache directory                     /home/developer/.ccache
cache hit (direct)                     2
cache hit (preprocessed)               0
cache miss                             2
files in cache                         4
cache size                            16 Kbytes
max cache size                       1.0 Gbytes
developer@crunchbang:~$ ccache --version
ccache version 3.1.7

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2011 Joel Rosdahl

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.

标签: ccache
2条回答
再贱就再见
2楼-- · 2019-08-12 04:21

Have you considered changing your Makefiles to use relative paths? You could use a technique like mentioned in this post to do this without having to make too much changes.

Note additionally: CCACHE_BASEDIR makes paths relative to the current working directory (something which perhaps could be specified a bit more clearly in the manpage). This means your 2 compilation commands will result in (with CCACHE_BASEDIR=/home/developer):

developer@crunchbang:~$ ccache g++ -c unique_name1/contest.cpp
developer@crunchbang:~$ ccache g++ -c unique_name2/contest.cpp

In other words: they will still be different. This issue will only be resolved if you compile inside the unique_name directories. For example

developer@crunchbang:~$ cd /home/developer/unique_name1 && ccache g++ -c /home/developer/unique_name1/contest.cpp
developer@crunchbang:~$ cd /home/developer/unique_name2 && ccache g++ -c /home/developer/unique_name2/contest.cpp

Will result in:

developer@crunchbang:~$ ccache g++ -c contest.cpp
developer@crunchbang:~$ ccache g++ -c contest.cpp
查看更多
成全新的幸福
3楼-- · 2019-08-12 04:39

The ccache misses(2) after the second compilation is the old statistics of last run. you could run "ccache -z" to clear last ccache statistics before you compile again.

查看更多
登录 后发表回答