Commit Diff


commit - ab2f42e760e128287c5e880a39c591845231922b
commit + c3b318d03e2208287f9ada2f6f9c759dfc0ba576
blob - b9d4f89656dd56b278729ad6c522d9c453d476da
blob + b8d6ef35517c4f74859324be5b8a53ec24206dd6
--- lib/delta_cache.c
+++ 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 *cach
 	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 *delt
 {
 	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 *delt
 		*delta_len = entry->delta_len;
 		return;
 	}
+
+	cache->cache_miss++;
 }