]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Show cache hit rate (%) in stats display
authorAnders Björklund <anders@itension.se>
Thu, 7 Jul 2016 18:41:43 +0000 (20:41 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 21 Jul 2016 20:20:06 +0000 (22:20 +0200)
Closes #94

stats.c

diff --git a/stats.c b/stats.c
index e9a8f09e86d59eae2c71bb36acd6ae476d7ab24b..22e634280452f5fe9a1e68dc8edb018d5eec5497 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -282,6 +282,9 @@ stats_summary(struct conf *conf)
 {
        int dir, i;
        struct counters *counters = counters_init(STATS_END);
+       unsigned direct = 0, preprocessed = 0;
+       unsigned hit, miss, total;
+       double percent;
 
        assert(conf);
 
@@ -323,6 +326,22 @@ stats_summary(struct conf *conf)
                } else {
                        printf("%8u\n", counters->data[stat]);
                }
+
+               if (stat == STATS_CACHEHIT_DIR) {
+                       direct = counters->data[stat];
+               } else if (stat == STATS_CACHEHIT_CPP) {
+                       preprocessed = counters->data[stat];
+               } else if (stat == STATS_TOCACHE) {
+                       miss = counters->data[stat];
+                       hit = direct + preprocessed;
+                       total = hit + miss;
+                       if (total > 0) {
+                               percent = (100.0f * hit) / total;
+                       } else {
+                               percent = 0.0f;
+                       }
+                       printf("cache hit rate                    %6.2f %%\n", percent);
+               }
        }
 
        if (conf->max_files != 0) {