add cache debug output for too large elements
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
diff --git a/lib/got_lib_object_cache.h b/lib/got_lib_object_cache.h
index a10ff39..4ac0ad0 100644
--- a/lib/got_lib_object_cache.h
+++ b/lib/got_lib_object_cache.h
@@ -39,6 +39,7 @@ struct got_object_cache {
int cache_hit;
int cache_miss;
int cache_evict;
+ int cache_toolarge;
};
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 4de69f1..5c1d8d2 100644
--- a/lib/object_cache.c
+++ b/lib/object_cache.c
@@ -159,8 +159,33 @@ got_object_cache_add(struct got_object_cache *cache, struct got_object_id *id, v
break;
}
- if (size > GOT_OBJECT_CACHE_MAX_ELEM_SIZE)
+ if (size > GOT_OBJECT_CACHE_MAX_ELEM_SIZE) {
+#ifdef GOT_OBJ_CACHE_DEBUG
+ char *id_str;
+ if (got_object_id_str(&id_str, id) != NULL)
+ return got_error_from_errno("got_object_id_str");
+ fprintf(stderr, "%s: not caching ", getprogname());
+ switch (cache->type) {
+ case GOT_OBJECT_CACHE_TYPE_OBJ:
+ fprintf(stderr, "object");
+ break;
+ case GOT_OBJECT_CACHE_TYPE_TREE:
+ fprintf(stderr, "tree");
+ break;
+ case GOT_OBJECT_CACHE_TYPE_COMMIT:
+ fprintf(stderr, "commit");
+ break;
+ case GOT_OBJECT_CACHE_TYPE_TAG:
+ fprintf(stderr, "tag");
+ break;
+ }
+ fprintf(stderr, " %s (%zd bytes; %zd MB)\n", id_str, size,
+ size/1024/1024);
+ free(id_str);
+#endif
+ cache->cache_toolarge++;
return NULL;
+ }
nelem = got_object_idset_num_elements(cache->idset);
if (nelem >= cache->size) {
@@ -245,10 +270,10 @@ static void
print_cache_stats(struct got_object_cache *cache, const char *name)
{
fprintf(stderr, "%s: %s cache: %d elements, %d searches, %d hits, "
- "%d missed, %d evicted\n", getprogname(), name,
+ "%d missed, %d evicted, %d too large\n", getprogname(), name,
got_object_idset_num_elements(cache->idset),
cache->cache_searches, cache->cache_hit,
- cache->cache_miss, cache->cache_evict);
+ cache->cache_miss, cache->cache_evict, cache->cache_toolarge);
}
const struct got_error *