From: Anders Björklund Date: Thu, 7 Jul 2016 18:41:43 +0000 (+0200) Subject: Show cache hit rate (%) in stats display X-Git-Tag: v3.3~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f27c98f438e5801c8cc8d99743ab78d1a8c4b86;p=thirdparty%2Fccache.git Show cache hit rate (%) in stats display Closes #94 --- diff --git a/stats.c b/stats.c index e9a8f09e8..22e634280 100644 --- 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) {