2 # This patch to djbdns 1.05 modifies the dnscache program to keep a
3 # counter of cache hits and cache misses.
5 # Two new fields are added to the ``stats'' output line:
6 # . the fifth number is the number of cache hits
7 # . the sixth number is the number of cache misses
9 # @400000003fa92ccc317d70f4 stats 3 1201 1 0 21 49
10 # indicates 21 hits and 49 misses.
12 # James Raftery <james@now.ie> 6 Nov. 2003
18 uint64 cache_motion = 0;
20 +/* record cache stats */
21 +/* James Raftery <james@now.ie> 6 Nov. 2003 */
22 +uint64 cache_hit = 0;
23 +uint64 cache_miss = 0;
28 @@ -112,15 +117,20 @@ char *cache_get(const char *key,unsigned
29 if (u > size - pos - 20 - keylen) cache_impossible();
33 return x + pos + 20 + keylen;
36 nextpos = prevpos ^ get4(pos);
39 - if (++loop > 100) return 0; /* to protect against hash flooding */
40 + if (++loop > 100) { /* to protect against hash flooding */
55 extern uint64 cache_motion;
57 +/* record cache stats */
58 +/* James Raftery <james@now.ie> 6 Nov. 2003 */
59 +extern uint64 cache_hit;
60 +extern uint64 cache_miss;
62 extern int cache_init(unsigned int);
63 extern void cache_set(const char *,unsigned int,const char *,unsigned int,uint32);
64 extern char *cache_get(const char *,unsigned int,unsigned int *,uint32 *);
67 @@ -279,6 +279,12 @@ void log_stats(void)
68 time_t cur = time(NULL);
69 extern uint64 numqueries;
70 extern uint64 cache_motion;
72 + /* record cache stats */
73 + /* James Raftery <james@now.ie> 6 Nov. 2003 */
74 + extern uint64 cache_hit;
75 + extern uint64 cache_miss;
80 @@ -290,6 +296,8 @@ void log_stats(void)
81 number(numqueries); space();
82 number(cache_motion); space();
83 number(uactive); space();
85 + number(tactive); space();
86 + number(cache_hit); space();