[or-cvs] [tor/master] Log the number and size of DNS cache entries on SIGUSR1.

Nick Mathewson nickm at seul.org
Sat May 23 03:35:04 UTC 2009


Author: Jacob Appelbaum <jacob at appelbaum.net>
Date: Fri, 22 May 2009 23:33:44 -0400
Subject: Log the number and size of DNS cache entries on SIGUSR1.
Commit: 75f963e9517ba8702fe1ed1d470e28b0462fb3d2

Specifically if you send SIGUSR1, it will add two lines to the log file:
May 22 07:41:59.576 [notice] Our DNS cache has 3364 entries.
May 22 07:41:59.576 [notice] Our DNS cache size is approximately 1022656
bytes.

[tweaked a bit by nickm]
---
 src/or/dns.c  |   25 +++++++++++++++++++++++++
 src/or/main.c |    1 +
 src/or/or.h   |    3 ++-
 3 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/src/or/dns.c b/src/or/dns.c
index 1742e3d..88d08a8 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -1612,6 +1612,31 @@ assert_resolve_ok(cached_resolve_t *resolve)
   }
 }
 
+/** Return the number of DNS cache entries as an int */
+static int
+dns_cache_entry_count(void)
+{
+   return HT_SIZE(&cache_root);
+}
+
+/** Log memory information about our internal DNS cache at level 'severity'. */
+void
+dump_dns_mem_usage(int severity)
+{
+  /* This should never be larger than INT_MAX. */
+  int hash_count = dns_cache_entry_count();
+  size_t hash_mem = sizeof(struct cached_resolve_t) * hash_count;
+  hash_mem += HT_MEM_USAGE(&cache_root);
+
+  /* Print out the count and estimated size of our &cache_root.  It undercounts
+     hostnames in cached reverse resolves.
+   */
+  log(severity, LD_MM, "Our DNS cache has %d entries.", hash_count);
+  log(severity, LD_MM, "Our DNS cache size is approximately %u bytes.",
+      (unsigned)hash_mem);
+}
+
+
 #ifdef DEBUG_DNS_CACHE
 /** Exit with an assertion if the DNS cache is corrupt. */
 static void
diff --git a/src/or/main.c b/src/or/main.c
index 69ed12f..b151b1f 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1588,6 +1588,7 @@ dumpmemusage(int severity)
       U64_PRINTF_ARG(rephist_total_alloc), rephist_total_num);
   dump_routerlist_mem_usage(severity);
   dump_cell_pool_usage(severity);
+  dump_dns_mem_usage(severity);
   buf_dump_freelist_sizes(severity);
   tor_log_mallinfo(severity);
 }
diff --git a/src/or/or.h b/src/or/or.h
index 7ac9e80..d5b36c8 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -483,7 +483,7 @@ typedef enum {
 #define CIRCUIT_PURPOSE_IS_ORIGIN(p) ((p)>_CIRCUIT_PURPOSE_OR_MAX)
 /** True iff the circuit purpose <b>p</b> is for a circuit that originated
  * here to serve as a client.  (Hidden services don't count here.) */
-#define CIRCUIT_PURPOSE_IS_CLIENT(p) \
+#define CIRCUIT_PURPOSE_IS_CLIENT(p)  \
   ((p)> _CIRCUIT_PURPOSE_OR_MAX &&    \
    (p)<=_CIRCUIT_PURPOSE_C_MAX)
 /** True iff the circuit_t <b>c</b> is actually an origin_circuit_t. */
@@ -3573,6 +3573,7 @@ int dns_resolve(edge_connection_t *exitconn);
 void dns_launch_correctness_checks(void);
 int dns_seems_to_be_broken(void);
 void dns_reset_correctness_checks(void);
+void dump_dns_mem_usage(int severity);
 
 /********************************* dnsserv.c ************************/
 
-- 
1.5.6.5



More information about the tor-commits mailing list