Hi list!
This patch adds 4 lines to the output of the unbound-control
[stats|stats_noreset]:
msg.cache.count=78
rrset.cache.count=346
infra.cache.count=14
key.cache.count=3
I added this functionality because I was often doing dump_cache and
then working on the output to find out some statistics on the cache
contents. Unfortunately this means locking the resolver because
dump_cache has to lock the slabhash.
This patch does not use any locks because it uses the counts
maintained within the structures.
Also it utilizes the fact that all these are struct slabhash type,
therefore I created only one generic function for that: size_t
count_slabhash_entries(struct slabhash *sh)
Please review this patch (on top of 1.4.22 tarball) for 1.4.23
Patch attached as well as inlined.
Best regards,
Maciej Soltysiak
diff -Nru /home/solt/orig/unbound-1.4.22.deb/daemon/remote.c
./unbound-1.4.22/daemon/remote.c
--- /home/solt/orig/unbound-1.4.22.deb/daemon/remote.c 2014-02-07
14:28:39.000000000 +0100
+++ ./unbound-1.4.22/daemon/remote.c 2014-08-01 14:06:49.530833070 +0200
@@ -874,6 +874,15 @@
(unsigned)s->svr.unwanted_queries)) return 0;
if(!ssl_printf(ssl, "unwanted.replies"SQ"%u\n",
(unsigned)s->svr.unwanted_replies)) return 0;
+ /* cache counts */
+ if(!ssl_printf(ssl, "msg.cache.count"SQ"%u\n",
+ (unsigned)s->svr.msg_cache_count)) return 0;
+ if(!ssl_printf(ssl, "rrset.cache.count"SQ"%u\n",
+ (unsigned)s->svr.rrset_cache_count)) return 0;
+ if(!ssl_printf(ssl, "infra.cache.count"SQ"%u\n",
+ (unsigned)s->svr.infra_cache_count)) return 0;
+ if(!ssl_printf(ssl, "key.cache.count"SQ"%u\n",
+ (unsigned)s->svr.key_cache_count)) return 0;
return 1;
}
diff -Nru /home/solt/orig/unbound-1.4.22.deb/daemon/stats.c
./unbound-1.4.22/daemon/stats.c
--- /home/solt/orig/unbound-1.4.22.deb/daemon/stats.c 2014-02-07
14:28:39.000000000 +0100
+++ ./unbound-1.4.22/daemon/stats.c 2014-08-01 14:34:05.066975149 +0200
@@ -56,6 +56,9 @@
#include "util/net_help.h"
#include "validator/validator.h"
#include "ldns/sbuffer.h"
+#include "services/cache/rrset.h"
+#include "services/cache/infra.h"
+#include "validator/val_kcache.h"
/** add timers and the values do not overflow or become negative */
static void
@@ -162,6 +165,12 @@
/* get and reset validator rrset bogus number */
s->svr.rrset_bogus = get_rrset_bogus(worker);
+ /* get cache sizes */
+ s->svr.msg_cache_count = count_slabhash_entries(worker->env.msg_cache);
+ s->svr.rrset_cache_count =
count_slabhash_entries(&worker->env.rrset_cache->table);
+ s->svr.infra_cache_count =
count_slabhash_entries(worker->env.infra_cache->hosts);
+ s->svr.key_cache_count =
count_slabhash_entries(worker->env.key_cache->slab);
(attachments)
unbound-cache-counts.diff (3.8 KB)