]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Log the number and size of DNS cache entries on SIGUSR1.
authorJacob Appelbaum <jacob@appelbaum.net>
Sat, 23 May 2009 03:33:44 +0000 (23:33 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 23 May 2009 03:33:44 +0000 (23:33 -0400)
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
src/or/main.c
src/or/or.h

index 1742e3dd4b7d5ecea4bf0239d6ac751db103a24a..88d08a8ffeb18f613bcabbdd827f8a1aebbf4883 100644 (file)
@@ -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
index 69ed12f12a9749266e0fe1de6a1a8943ceafa129..b151b1f6663906dd54c885f94d12af94b231421d 100644 (file)
@@ -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);
 }
index 7ac9e8000438b2be4fa5e897c174777c0dc6b4ab..d5b36c85a6f067d01b8f337e416a5f7eeb2e441c 100644 (file)
@@ -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 ************************/