summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-12-13 20:32:15 +0100
committerJoel Rosdahl <joel@rosdahl.net>2022-12-13 20:38:38 +0100
commit63e2517d39e679c0f8d23cac54311406d3ca243b (patch)
treeeb32be439343b68265831fab7241fe05ca340ae8
parent5d00143e447a50ef9f4709e685c9f0776431c00b (diff)
downloadccache-63e2517d39e679c0f8d23cac54311406d3ca243b.tar.gz
fix: Fix reporting of local/remote cache misses in depend mode
-rw-r--r--src/ccache.cpp5
-rw-r--r--src/storage/Storage.cpp5
-rw-r--r--src/storage/local/LocalStorage.cpp5
-rw-r--r--test/suites/remote_file.bash55
4 files changed, 70 insertions, 0 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp
index c063a58f..8791f788 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -631,6 +631,11 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
static std::optional<Digest>
result_key_from_depfile(Context& ctx, Hash& hash)
{
+ // Make sure that result hash will always be different from the manifest hash
+ // since there otherwise may a storage key collision (in case the dependency
+ // file is empty).
+ hash.hash_delimiter("result");
+
const auto file_content =
util::read_file<std::string>(ctx.args_info.output_dep);
if (!file_content) {
diff --git a/src/storage/Storage.cpp b/src/storage/Storage.cpp
index 5c843db2..da707ea6 100644
--- a/src/storage/Storage.cpp
+++ b/src/storage/Storage.cpp
@@ -463,6 +463,11 @@ Storage::get_from_remote_storage(const Digest& key,
local.increment_statistic(core::Statistic::remote_storage_read_miss);
if (type == core::CacheEntryType::result) {
local.increment_statistic(core::Statistic::remote_storage_miss);
+ } else if (m_config.depend_mode()) {
+ // With the depend mode enabled, a missing manifest means that we can't
+ // even try to look up a result, so note the miss already now.
+ ASSERT(type == core::CacheEntryType::manifest);
+ local.increment_statistic(core::Statistic::remote_storage_miss);
}
}
}
diff --git a/src/storage/local/LocalStorage.cpp b/src/storage/local/LocalStorage.cpp
index 274a4460..f1984caa 100644
--- a/src/storage/local/LocalStorage.cpp
+++ b/src/storage/local/LocalStorage.cpp
@@ -223,6 +223,11 @@ LocalStorage::get(const Digest& key, const core::CacheEntryType type)
if (type == core::CacheEntryType::result) {
increment_statistic(return_value ? core::Statistic::local_storage_hit
: core::Statistic::local_storage_miss);
+ } else if (m_config.depend_mode() && !return_value) {
+ // With the depend mode enabled, a missing manifest means that we can't even
+ // try to look up a result, so note the miss already now.
+ ASSERT(type == core::CacheEntryType::manifest);
+ increment_statistic(core::Statistic::local_storage_miss);
}
return return_value;
diff --git a/test/suites/remote_file.bash b/test/suites/remote_file.bash
index c4a8c1d2..a48ae561 100644
--- a/test/suites/remote_file.bash
+++ b/test/suites/remote_file.bash
@@ -195,6 +195,61 @@ SUITE_remote_file() {
expect_file_count 3 '*' remote # CACHEDIR.TAG + result + manifest
# -------------------------------------------------------------------------
+ TEST "Depend mode"
+
+ export CCACHE_DEPEND=1
+
+ # Compile and send result to local and remote storage.
+ $CCACHE_COMPILE -MMD -c test.c
+ expect_stat direct_cache_hit 0
+ expect_stat cache_miss 1
+ expect_stat files_in_cache 2
+ expect_stat local_storage_hit 0
+ expect_stat local_storage_miss 1
+ expect_stat local_storage_read_hit 0
+ expect_stat local_storage_read_miss 1 # only manifest
+ expect_stat local_storage_write 2 # result + manifest
+ expect_stat remote_storage_hit 0
+ expect_stat remote_storage_miss 1
+ expect_stat remote_storage_read_hit 0
+ expect_stat remote_storage_read_miss 1 # only manifest
+ expect_stat remote_storage_write 2 # result + manifest
+
+ # Get result from local storage.
+ $CCACHE_COMPILE -MMD -c test.c
+ expect_stat direct_cache_hit 1
+ expect_stat cache_miss 1
+ expect_stat local_storage_hit 1
+ expect_stat local_storage_miss 1
+ expect_stat local_storage_read_hit 2 # result + manifest
+ expect_stat local_storage_read_miss 1 # manifest
+ expect_stat local_storage_write 2 # result + manifest
+ expect_stat remote_storage_hit 0
+ expect_stat remote_storage_miss 1
+ expect_stat remote_storage_read_hit 0
+ expect_stat remote_storage_read_miss 1
+ expect_stat remote_storage_write 2
+
+ # Clear local storage.
+ $CCACHE -C >/dev/null
+
+ # Get result from remote storage, copying it to local storage.
+ # TERM=xterm-256color gdb --args $CCACHE_COMPILE -MMD -c test.c
+ $CCACHE_COMPILE -MMD -c test.c
+ expect_stat direct_cache_hit 2
+ expect_stat cache_miss 1
+ expect_stat local_storage_hit 1
+ expect_stat local_storage_miss 3
+ expect_stat local_storage_read_hit 2
+ expect_stat local_storage_read_miss 3
+ expect_stat local_storage_write 4
+ expect_stat remote_storage_hit 1
+ expect_stat remote_storage_miss 1
+ expect_stat remote_storage_read_hit 2 # result + manifest
+ expect_stat remote_storage_read_miss 1
+ expect_stat remote_storage_write 2 # result + manifest
+
+ # -------------------------------------------------------------------------
TEST "umask"
export CCACHE_UMASK=042