enum class FromCacheCallMode { direct, cpp };
// Try to return the compile result from cache.
-static optional<Statistic>
+static bool
from_cache(Context& ctx, FromCacheCallMode mode, const Digest& result_key)
{
UmaskScope umask_scope(ctx.original_umask);
// The user might be disabling cache hits.
if (ctx.config.recache()) {
- return nullopt;
+ return false;
}
// If we're using Clang, we can't trust a precompiled header object based on
&& ctx.args_info.output_is_precompiled_header
&& mode == FromCacheCallMode::cpp) {
LOG_RAW("Not considering cached precompiled header in preprocessor mode");
- return nullopt;
+ return false;
}
MTR_BEGIN("cache", "from_cache");
const auto result_path =
ctx.storage.get(result_key, core::CacheEntryType::result);
if (!result_path) {
- return nullopt;
+ return false;
}
Result::Reader result_reader(*result_path);
MTR_END("cache", "from_cache");
if (error) {
LOG("Failed to get result from cache: {}", *error);
- return nullopt;
+ return false;
}
LOG_RAW("Succeeded getting cached result");
-
- return mode == FromCacheCallMode::direct ? Statistic::direct_cache_hit
- : Statistic::preprocessed_cache_hit;
+ return true;
}
// Find the real compiler and put it into ctx.orig_args[0]. We just search the
MTR_END("hash", "direct_hash");
if (result_key) {
// If we can return from cache at this point then do so.
- auto result = from_cache(ctx, FromCacheCallMode::direct, *result_key);
- if (result) {
- return *result;
+ const bool found =
+ from_cache(ctx, FromCacheCallMode::direct, *result_key);
+ if (found) {
+ return Statistic::direct_cache_hit;
}
// Wasn't able to return from cache at this point. However, the result
// Add result to manifest later.
put_result_in_manifest = true;
}
+
+ ctx.storage.primary.increment_statistic(Statistic::direct_cache_miss);
}
if (ctx.config.read_only_direct()) {
}
// If we can return from cache at this point then do.
- const auto result = from_cache(ctx, FromCacheCallMode::cpp, *result_key);
- if (result) {
+ const auto found = from_cache(ctx, FromCacheCallMode::cpp, *result_key);
+ if (found) {
if (manifest_key && put_result_in_manifest) {
update_manifest_file(ctx, *manifest_key, *result_key);
}
- return *result;
+ return Statistic::preprocessed_cache_hit;
}
+
+ ctx.storage.primary.increment_statistic(Statistic::preprocessed_cache_miss);
}
if (ctx.config.read_only()) {
unsupported_code_directive = 30,
stats_zeroed_timestamp = 31,
could_not_use_modules = 32,
+ direct_cache_miss = 33,
+ preprocessed_cache_miss = 34,
END
};
STATISTICS_FIELD(
preprocessed_cache_hit, "cache hit (preprocessed)", FLAG_ALWAYS),
STATISTICS_FIELD(cache_miss, "cache miss", FLAG_ALWAYS),
+ STATISTICS_FIELD(direct_cache_miss, "cache miss (direct)"),
+ STATISTICS_FIELD(preprocessed_cache_miss, "cache miss (preprocessed)"),
STATISTICS_FIELD(called_for_link, "called for link"),
STATISTICS_FIELD(called_for_preprocessing, "called for preprocessing"),
STATISTICS_FIELD(multiple_source_files, "multiple source files"),
$CCACHE_COMPILE -c test1.c
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 0
+ expect_stat preprocessed_cache_miss 1
expect_stat files_in_cache 1
expect_equal_object_files reference_test1.o test1.o
$CCACHE_COMPILE -c test1.c
expect_stat preprocessed_cache_hit 1
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 0
+ expect_stat preprocessed_cache_miss 1
expect_stat files_in_cache 1
expect_equal_object_files reference_test1.o test1.o
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 0
expect_stat files_in_cache 2 # result + manifest
CCACHE_DEPEND=1 $CCACHE_COMPILE $DEPSFLAGS_CCACHE -c test.c
expect_stat direct_cache_hit 1
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 0
expect_stat files_in_cache 2
# -------------------------------------------------------------------------
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 1
expect_stat files_in_cache 2 # result + manifest
expect_equal_object_files reference_test.o test.o
expect_stat direct_cache_hit 1
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 1
expect_stat files_in_cache 2
expect_equal_object_files reference_test.o test.o
expect_newer_than $manifest_file test.c
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 1
CCACHE_READONLY_DIRECT=1 $CCACHE_COMPILE -c test.c -o test.o
expect_stat direct_cache_hit 1
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 1
# -------------------------------------------------------------------------
TEST "Direct miss doesn't lead to preprocessed hit"
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 1
+ expect_stat direct_cache_miss 1
+ expect_stat preprocessed_cache_miss 1
CCACHE_READONLY_DIRECT=1 $CCACHE_COMPILE -DFOO -c test.c -o test.o
expect_stat direct_cache_hit 0
expect_stat preprocessed_cache_hit 0
expect_stat cache_miss 2
+ expect_stat direct_cache_miss 2
+ expect_stat preprocessed_cache_miss 1
}
expect_content stats.log "# test.c
cache_miss
+direct_cache_miss
+preprocessed_cache_miss
# test.c
direct_cache_hit"
}