我有一个与ccache配置相关的问题。在我们的开发环境中,我们有数百个使用绝对路径构建对象的make文件。
我想要加速这个过程,并使用ccache。不幸的是,当从不同的位置编译时,我会看到缓存未命中。以下是源文件放在不同目录中的简化情况的示例。如何设置ccache才能获得正确的命中率?
我尝试设置CCACHE_BASEDIR变量,但没有成功:
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.发布于 2014-08-14 16:19:15
您是否考虑过将Makefiles更改为使用相对路径?您可以使用像前面提到的in this post这样的技术来实现这一点,而不必进行太多更改。
另外注意: CCACHE_BASEDIR的路径是相对于当前工作目录的(这一点也许可以在手册页中更清楚地指定)。这意味着您的两个编译命令将导致(使用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发布于 2019-06-11 11:46:47
第二次编译后的ccache未命中(2)是上次运行的旧统计数据。在重新编译之前,您可以运行"ccache -z“来清除上次的缓存统计数据。
https://stackoverflow.com/questions/24713745
复制相似问题