count cache eviction events in cache debug stats
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/lib/got_lib_object_cache.h b/lib/got_lib_object_cache.h
index 871bc3c..7c8c41b 100644
--- a/lib/got_lib_object_cache.h
+++ b/lib/got_lib_object_cache.h
@@ -35,6 +35,7 @@ struct got_object_cache {
size_t size;
int cache_hit;
int cache_miss;
+ int cache_evict;
};
const struct got_error *got_object_cache_init(struct got_object_cache *,
diff --git a/lib/object_cache.c b/lib/object_cache.c
index 1e3d2dc..ed74d0d 100644
--- a/lib/object_cache.c
+++ b/lib/object_cache.c
@@ -87,6 +87,7 @@ got_object_cache_add(struct got_object_cache *cache, struct got_object_id *id, v
break;
}
free(ce);
+ cache->cache_evict++;
}
ce = calloc(1, sizeof(*ce));
@@ -141,9 +142,10 @@ got_object_cache_get(struct got_object_cache *cache, struct got_object_id *id)
static void
print_cache_stats(struct got_object_cache *cache, const char *name)
{
- fprintf(stderr, "%s cache: %d elements, %d hits, %d missed\n",
+ fprintf(stderr, "%s cache: %d elements, %d hits, %d missed, "
+ "%d evicted\n",
name, got_object_idcache_num_elements(cache->idcache),
- cache->cache_hit, cache->cache_miss);
+ cache->cache_hit, cache->cache_miss, cache->cache_evict);
}
void check_refcount(struct got_object_id *id, void *data, void *arg)