3

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.
4

2 回答 2

4

您是否考虑过更改 Makefile 以使用相对路径?您可以使用本文中提到的技术执行此操作,而无需进行太多更改。

另外请注意:CCACHE_BASEDIR 使路径相对于当前工作目录(可能可以在手册页中更清楚地指定一些内容)。这意味着您的 2 个编译命令将导致(使用 CCACHE_BASEDIR=/home/developer):

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

换句话说:它们仍然会有所不同。只有在 unique_name 目录中编译时,此问题才会得到解决。例如

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

将导致:

developer@crunchbang:~$ ccache g++ -c contest.cpp
developer@crunchbang:~$ ccache g++ -c contest.cpp
于 2014-08-14T08:19:15.023 回答
0

第二次编译后的 ccache miss(2) 是上次运行的旧统计信息。您可以在再次编译之前运行“ccache -z”来清除最后的 ccache 统计信息。

于 2019-06-11T03:46:46.870 回答