Commit 315fa2b2ac76949450623ae5afdd37942ae689ee

Stefan Sperling 2018-09-15T20:19:18

count cache eviction events in cache debug stats

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)