From 0bbf7d0a231e00c9a54824a28822b1fa17a341f9 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Tue, 14 Dec 2010 13:35:44 +0000 Subject: [PATCH] implement & document packetcache-bytes and cache-bytes, which return the estimated pre-malloc bytesize usage of these caches git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1750 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/docs/pdns.sgml | 2 ++ pdns/rec_channel_rec.cc | 43 +++++++++++++++++++++++++++++++++++------ pdns/recpacketcache.cc | 11 +++++++++++ pdns/recpacketcache.hh | 1 + 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pdns/docs/pdns.sgml b/pdns/docs/pdns.sgml index 44639a566..220e853e3 100644 --- a/pdns/docs/pdns.sgml +++ b/pdns/docs/pdns.sgml @@ -9807,6 +9807,7 @@ answers100-1000 counts the number of queries answered within 1 second answers10-100 counts the number of queries answered within 100 miliseconds answers1-10 counts the number of queries answered within 10 miliseconds answers-slow counts the number of queries answered after 1 second +cache-bytes Size of the cache in bytes (since 3.3.1) cache-entries shows the number of entries in the cache cache-hits counts the number of cache hits since starting cache-misses counts the number of cache misses since starting @@ -9823,6 +9824,7 @@ nsset-invalidations number of times an nsset was dropped because it no longer wo nxdomain-answers counts the number of times it answered NXDOMAIN since starting outgoing-timeouts counts the number of timeouts on outgoing UDP queries since starting over-capacity-drops Questions dropped because over maximum concurrent query limit (since 3.2) +packetcache-bytes Size of the packet cache in bytes (since 3.3.1) packetcache-entries Size of packet cache (since 3.2) packetcache-hits Packet cache hits (since 3.2) packetcache-misses Packet cache misses (since 3.2) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 8f196cc28..233f193fc 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -298,11 +298,22 @@ uint64_t* pleaseGetCacheSize() return new uint64_t(t_RC->size()); } +uint64_t* pleaseGetCacheBytes() +{ + return new uint64_t(t_RC->bytes()); +} + + uint64_t doGetCacheSize() { return broadcastAccFunction(pleaseGetCacheSize); } +uint64_t doGetCacheBytes() +{ + return broadcastAccFunction(pleaseGetCacheBytes); +} + uint64_t* pleaseGetCacheHits() { return new uint64_t(t_RC->cacheHits); @@ -324,18 +335,28 @@ uint64_t doGetCacheMisses() } - - uint64_t* pleaseGetPacketCacheSize() { return new uint64_t(t_packetCache->size()); } +uint64_t* pleaseGetPacketCacheBytes() +{ + return new uint64_t(t_packetCache->bytes()); +} + + uint64_t doGetPacketCacheSize() { return broadcastAccFunction(pleaseGetPacketCacheSize); } +uint64_t doGetPacketCacheBytes() +{ + return broadcastAccFunction(pleaseGetPacketCacheBytes); +} + + uint64_t* pleaseGetPacketCacheHits() { return new uint64_t(t_packetCache->d_hits); @@ -356,6 +377,13 @@ uint64_t doGetPacketCacheMisses() return broadcastAccFunction(pleaseGetPacketCacheMisses); } +uint64_t doGetMallocated() +{ + // this turned out to be broken +/* struct mallinfo mi = mallinfo(); + return mi.uordblks; */ + return 0; +} RecursorControlParser::RecursorControlParser() { @@ -365,12 +393,14 @@ RecursorControlParser::RecursorControlParser() addGetStat("cache-hits", doGetCacheHits); addGetStat("cache-misses", doGetCacheMisses); addGetStat("cache-entries", doGetCacheSize); + addGetStat("cache-bytes", doGetCacheBytes); addGetStat("packetcache-hits", doGetPacketCacheHits); addGetStat("packetcache-misses", doGetPacketCacheMisses); addGetStat("packetcache-entries", doGetPacketCacheSize); + addGetStat("packetcache-bytes", doGetPacketCacheBytes); - + addGetStat("malloc-bytes", doGetMallocated); addGetStat("servfail-answers", &g_stats.servFails); addGetStat("nxdomain-answers", &g_stats.nxDomains); @@ -456,6 +486,8 @@ static void doExit() static void doExitNicely() { + //extern void printCallers(); + // printCallers(); doExitGeneric(true); } @@ -530,8 +562,7 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="quit-nicely") { *command=&doExitNicely; return "bye nicely\n"; - } - + } if(cmd=="dump-cache") return doDumpCache(begin, end); @@ -577,6 +608,6 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="reload-zones") { return reloadAuthAndForwards(); } - + return "Unknown command '"+cmd+"'\n"; } diff --git a/pdns/recpacketcache.cc b/pdns/recpacketcache.cc index 37a1af51c..4c80435c3 100644 --- a/pdns/recpacketcache.cc +++ b/pdns/recpacketcache.cc @@ -1,4 +1,5 @@ #include +#include #include "recpacketcache.hh" #include "cachecleaner.hh" #include "dns.hh" @@ -62,6 +63,16 @@ uint64_t RecursorPacketCache::size() return d_packetCache.size(); } +uint64_t RecursorPacketCache::bytes() +{ + uint64_t sum=0; + BOOST_FOREACH(const struct Entry& e, d_packetCache) { + sum += sizeof(e) + e.d_packet.length() + 4; + } + return sum; +} + + void RecursorPacketCache::doPruneTo(unsigned int maxCached) { pruneCollection(d_packetCache, maxCached); diff --git a/pdns/recpacketcache.hh b/pdns/recpacketcache.hh index a35f36a3a..881ff8a28 100644 --- a/pdns/recpacketcache.hh +++ b/pdns/recpacketcache.hh @@ -26,6 +26,7 @@ public: void prune(); uint64_t d_hits, d_misses; uint64_t size(); + uint64_t bytes(); private: -- 2.40.0