summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/or/dns.c25
-rw-r--r--src/or/main.c1
-rw-r--r--src/or/or.h3
3 files changed, 28 insertions, 1 deletions
diff --git a/src/or/dns.c b/src/or/dns.c
index 1742e3dd4b..88d08a8ffe 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 69ed12f12a..b151b1f666 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 7ac9e80004..d5b36c85a6 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 ************************/