add debug stats to delta cache
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/lib/delta_cache.c b/lib/delta_cache.c
index b9d4f89..b8d6ef3 100644
--- a/lib/delta_cache.c
+++ b/lib/delta_cache.c
@@ -50,6 +50,11 @@ struct got_delta_cache {
int nelem;
int maxelem;
size_t maxelemsize;
+ int cache_search;
+ int cache_hit;
+ int cache_miss;
+ int cache_evict;
+ int cache_toolarge;
};
struct got_delta_cache *
@@ -72,6 +77,12 @@ got_delta_cache_free(struct got_delta_cache *cache)
{
struct got_delta_cache_element *entry;
+#ifdef GOT_OBJ_CACHE_DEBUG
+ fprintf(stderr, "%s: delta cache: %d elements, %d searches, %d hits, "
+ "%d missed, %d evicted, %d too large\n", getprogname(), cache->nelem,
+ cache->cache_search, cache->cache_hit, cache->cache_miss,
+ cache->cache_evict, cache->cache_toolarge);
+#endif
while (!TAILQ_EMPTY(&cache->entries)) {
entry = TAILQ_FIRST(&cache->entries);
TAILQ_REMOVE(&cache->entries, entry, entry);
@@ -94,6 +105,7 @@ remove_least_used_element(struct got_delta_cache *cache)
free(entry->delta_data);
free(entry);
cache->nelem--;
+ cache->cache_evict++;
}
@@ -103,8 +115,10 @@ got_delta_cache_add(struct got_delta_cache *cache,
{
struct got_delta_cache_element *entry;
- if (delta_len > cache->maxelemsize)
+ if (delta_len > cache->maxelemsize) {
+ cache->cache_toolarge++;
return got_error(GOT_ERR_NO_SPACE);
+ }
if (cache->nelem >= cache->maxelem)
remove_least_used_element(cache);
@@ -128,11 +142,13 @@ got_delta_cache_get(uint8_t **delta_data, size_t *delta_len,
{
struct got_delta_cache_element *entry;
+ cache->cache_search++;
*delta_data = NULL;
*delta_len = 0;
TAILQ_FOREACH(entry, &cache->entries, entry) {
if (entry->delta_data_offset != delta_data_offset)
continue;
+ cache->cache_hit++;
if (entry != TAILQ_FIRST(&cache->entries)) {
TAILQ_REMOVE(&cache->entries, entry, entry);
TAILQ_INSERT_HEAD(&cache->entries, entry, entry);
@@ -141,4 +157,6 @@ got_delta_cache_get(uint8_t **delta_data, size_t *delta_len,
*delta_len = entry->delta_len;
return;
}
+
+ cache->cache_miss++;
}