From: Joel Rosdahl Date: Mon, 9 May 2022 16:43:03 +0000 (+0200) Subject: fix: Correctly represent statistics counters > 1 in log and stats log X-Git-Tag: v4.6.1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8885a2e17f0d2e071f494c5f409a984f3f9448e;p=thirdparty%2Fccache.git fix: Correctly represent statistics counters > 1 in log and stats log --- diff --git a/src/core/Statistics.cpp b/src/core/Statistics.cpp index 7786b2614..c1f0a52c7 100644 --- a/src/core/Statistics.cpp +++ b/src/core/Statistics.cpp @@ -162,8 +162,10 @@ Statistics::get_statistics_ids() const { std::vector result; for (const auto& field : k_statistics_fields) { - if (m_counters.get(field.statistic) != 0 && !(field.flags & FLAG_NOZERO)) { - result.emplace_back(field.id); + if (!(field.flags & FLAG_NOZERO)) { + for (size_t i = 0; i < m_counters.get(field.statistic); ++i) { + result.emplace_back(field.id); + } } } std::sort(result.begin(), result.end()); diff --git a/test/suites/stats_log.bash b/test/suites/stats_log.bash index e90efaf54..1ad3b930d 100644 --- a/test/suites/stats_log.bash +++ b/test/suites/stats_log.bash @@ -10,18 +10,26 @@ SUITE_stats_log() { $CCACHE_COMPILE -c test.c expect_stat direct_cache_hit 0 + expect_stat preprocessed_cache_miss 1 expect_stat cache_miss 1 + expect_stat primary_storage_hit 0 + expect_stat primary_storage_miss 2 $CCACHE_COMPILE -c test.c expect_stat direct_cache_hit 1 + expect_stat preprocessed_cache_miss 1 expect_stat cache_miss 1 + expect_stat primary_storage_hit 2 + expect_stat primary_storage_miss 2 expect_content stats.log "# test.c cache_miss direct_cache_miss preprocessed_cache_miss primary_storage_miss +primary_storage_miss # test.c direct_cache_hit +primary_storage_hit primary_storage_hit" }