我有一个与 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.
您是否考虑过更改 Makefile 以使用相对路径?你可以使用提到的技术在这篇文章中 https://stackoverflow.com/questions/2564634/bash-convert-absolute-path-into-relative-path-given-a-current-directory无需进行太多更改即可做到这一点。
另外请注意: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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)