From: Joel Rosdahl Date: Sun, 8 Aug 2021 15:35:18 +0000 (+0200) Subject: feat: Add statistics for direct/preprocessed cache miss X-Git-Tag: v4.4~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9567b9aa1834e44eb20709a26e641cf8766393f;p=thirdparty%2Fccache.git feat: Add statistics for direct/preprocessed cache miss --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 98a425c59..1d629b3c6 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1713,14 +1713,14 @@ calculate_result_and_manifest_key(Context& ctx, enum class FromCacheCallMode { direct, cpp }; // Try to return the compile result from cache. -static optional +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 @@ -1735,7 +1735,7 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Digest& result_key) && 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"); @@ -1744,7 +1744,7 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Digest& result_key) 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); @@ -1755,13 +1755,11 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Digest& result_key) 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 @@ -2098,9 +2096,10 @@ do_cache_compilation(Context& ctx, const char* const* argv) 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 @@ -2112,6 +2111,8 @@ do_cache_compilation(Context& ctx, const char* const* argv) // 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()) { @@ -2160,13 +2161,15 @@ do_cache_compilation(Context& ctx, const char* const* argv) } // 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()) { diff --git a/src/core/Statistic.hpp b/src/core/Statistic.hpp index 2ad3cd7b0..43cc94f16 100644 --- a/src/core/Statistic.hpp +++ b/src/core/Statistic.hpp @@ -55,6 +55,8 @@ enum class Statistic { unsupported_code_directive = 30, stats_zeroed_timestamp = 31, could_not_use_modules = 32, + direct_cache_miss = 33, + preprocessed_cache_miss = 34, END }; diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index 6ff89afcc..ce3a24b18 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -79,6 +79,8 @@ const StatisticsField k_statistics_fields[] = { 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"), diff --git a/test/suites/base.bash b/test/suites/base.bash index 7251c20e9..84f51a48c 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -7,12 +7,16 @@ base_tests() { $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 diff --git a/test/suites/depend.bash b/test/suites/depend.bash index 66df696c1..24944acbc 100644 --- a/test/suites/depend.bash +++ b/test/suites/depend.bash @@ -99,6 +99,8 @@ SUITE_depend() { 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 @@ -106,6 +108,8 @@ SUITE_depend() { 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 # ------------------------------------------------------------------------- diff --git a/test/suites/direct.bash b/test/suites/direct.bash index 616c03362..660ee07b6 100644 --- a/test/suites/direct.bash +++ b/test/suites/direct.bash @@ -33,6 +33,8 @@ SUITE_direct() { 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 @@ -43,6 +45,8 @@ SUITE_direct() { 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 diff --git a/test/suites/readonly_direct.bash b/test/suites/readonly_direct.bash index 684767232..738c2bf7c 100644 --- a/test/suites/readonly_direct.bash +++ b/test/suites/readonly_direct.bash @@ -21,11 +21,15 @@ SUITE_readonly_direct() { 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" @@ -34,9 +38,13 @@ SUITE_readonly_direct() { 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 } diff --git a/test/suites/stats_log.bash b/test/suites/stats_log.bash index 54a09a6c6..a55de6e06 100644 --- a/test/suites/stats_log.bash +++ b/test/suites/stats_log.bash @@ -18,6 +18,8 @@ SUITE_stats_log() { expect_content stats.log "# test.c cache_miss +direct_cache_miss +preprocessed_cache_miss # test.c direct_cache_hit" }