diff options
author | Jacob Appelbaum <jacob@appelbaum.net> | 2009-05-22 23:33:44 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-05-22 23:33:44 -0400 |
commit | 75f963e9517ba8702fe1ed1d470e28b0462fb3d2 (patch) | |
tree | 1ca1f604bb51ad4d8cebfabf6b6927b8b8b0b8f2 /src | |
parent | 793e97bb2a610dbd4cf8cfb2795f8b680d55a116 (diff) | |
download | tor-75f963e9517ba8702fe1ed1d470e28b0462fb3d2.tar.gz tor-75f963e9517ba8702fe1ed1d470e28b0462fb3d2.zip |
Log the number and size of DNS cache entries on SIGUSR1.
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]
Diffstat (limited to 'src')
-rw-r--r-- | src/or/dns.c | 25 | ||||
-rw-r--r-- | src/or/main.c | 1 | ||||
-rw-r--r-- | 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 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 ************************/ |