aboutsummaryrefslogtreecommitdiff
path: root/src/dicache.c
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2025-08-03 15:02:41 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2025-08-11 21:43:10 +0200
commit1a885c25f7ad7eb217d9b2f0ab477ab1b7be6433 (patch)
tree25b8a6c130e4925ca448cc0f035887bfe9c2b613 /src/dicache.c
parentc3431cc169a7bc24dcff845aeda3f7f30a8ad1fa (diff)
Add about:dicache for decompressed image cache
The dicache holds the decompressed buffers for each image and it often is the main cause for memory consumption in Dillo. The current algorithm for evicting entries waits until a image has no references and at least three pages were opened before removing the entry.
Diffstat (limited to 'src/dicache.c')
-rw-r--r--src/dicache.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/dicache.c b/src/dicache.c
index e53fb011..e83d2d72 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -2,7 +2,7 @@
* File: dicache.c
*
* Copyright 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -191,6 +191,14 @@ static void Dicache_remove(const DilloUrl *Url, int version)
dFree(entry);
}
+static int Dicache_is_last_ref(DICacheEntry *entry)
+{
+ if (entry->v_imgbuf)
+ return a_Imgbuf_last_reference(entry->v_imgbuf);
+
+ return 0;
+}
+
/**
* Unrefs the counter of a dicache entry (it counts cache clients).
* If there're no clients and no imgbuf, remove the entry.
@@ -599,3 +607,49 @@ void a_Dicache_freeall(void)
}
dList_free(CachedIMGs);
}
+
+Dstr *a_Dicache_stats(void)
+{
+ long bytesCached = 0L;
+ Dstr *s = dStr_new(
+ "<!DOCTYPE HTML>\n"
+ "<html>\n"
+ "<head><title>Decompressed Image Cache</title></head>\n"
+ "<body>\n");
+
+ int n = dList_length(CachedIMGs);
+ dStr_sprintfa(s, "<h1>Decompressed Image Cache (%d)</h1>\n", n);
+
+ dStr_append(s, "<table>\n");
+ dStr_append(s, "<tr>\n");
+ dStr_append(s, "<th><span title='Survival Counter'>S</span></th>\n");
+ dStr_append(s, "<th><span title='Last Reference'>L</span></th>\n");
+ dStr_append(s, "<th>Area</th>\n");
+ dStr_append(s, "<th>Size</th>\n");
+ dStr_append(s, "<th>URL</th>\n");
+ dStr_append(s, "</tr>\n");
+ for (int i = 0; i < n; i++) {
+ DICacheEntry *e = dList_nth_data(CachedIMGs, i);
+ dStr_append(s, "<tr>\n");
+ dStr_sprintfa(s, "<td style='text-align:right'>%hd</td>", e->SurvCleanup);
+ dStr_sprintfa(s, "<td style='text-align:right'>%d</td>", Dicache_is_last_ref(e));
+ dStr_sprintfa(s, "<td style='text-align:right'>%ux%u</td>", e->width, e->height);
+ dStr_sprintfa(s, "<td style='text-align:right'>%.2f KiB</td>\n",
+ e->TotalSize / 1024.0f);
+ dStr_sprintfa(s, "<td><a href='%s'>", URL_STR(e->url));
+ dStr_shorten(s, URL_STR(e->url), 60);
+ dStr_append(s, "</a></td>\n");
+ dStr_append(s, "</tr>\n");
+ bytesCached += (long) e->TotalSize;
+ }
+ dStr_append(s, "</table>\n");
+ float mb = (float) bytesCached / (1024.0f * 1024.0f);
+
+ dStr_sprintfa(s, "<p>Total cached: %.2f MiB</p>\n", mb);
+
+ dStr_append(s,
+ "</body>\n"
+ "</html>\n");
+
+ return s;
+}