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/or/dns.c | |
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/or/dns.c')
-rw-r--r-- | src/or/dns.c | 25 |
1 files changed, 25 insertions, 0 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 |