summaryrefslogtreecommitdiffstats
path: root/net/djbdns/patches/110-dnscache-cachestats.patch
blob: 5404719dfe06ff78cea519136b031f109e8073bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# This patch to djbdns 1.05 modifies the dnscache program to keep a
# counter of cache hits and cache misses.
#
# Two new fields are added to the ``stats'' output line:
#  . the fifth number is the number of cache hits
#  . the sixth number is the number of cache misses
# e.g.
#  @400000003fa92ccc317d70f4 stats 3 1201 1 0 21 49
# indicates 21 hits and 49 misses.
#
# James Raftery <james@now.ie>  6 Nov. 2003
#
--- a/cache.c
+++ b/cache.c
@@ -7,6 +7,11 @@
 
 uint64 cache_motion = 0;
 
+/* record cache stats */
+/* James Raftery <james@now.ie> 6 Nov. 2003 */
+uint64 cache_hit = 0;
+uint64 cache_miss = 0;
+
 static char *x = 0;
 static uint32 size;
 static uint32 hsize;
@@ -112,15 +117,20 @@ char *cache_get(const char *key,unsigned
         if (u > size - pos - 20 - keylen) cache_impossible();
         *datalen = u;
 
+        cache_hit++;
         return x + pos + 20 + keylen;
       }
     }
     nextpos = prevpos ^ get4(pos);
     prevpos = pos;
     pos = nextpos;
-    if (++loop > 100) return 0; /* to protect against hash flooding */
+    if (++loop > 100) { /* to protect against hash flooding */
+      cache_miss++;
+      return 0;
+    }
   }
 
+  cache_miss++;
   return 0;
 }
 
--- a/cache.h
+++ b/cache.h
@@ -5,6 +5,12 @@
 #include "uint64.h"
 
 extern uint64 cache_motion;
+
+/* record cache stats */
+/* James Raftery <james@now.ie> 6 Nov. 2003 */
+extern uint64 cache_hit;
+extern uint64 cache_miss;
+
 extern int cache_init(unsigned int);
 extern void cache_set(const char *,unsigned int,const char *,unsigned int,uint32);
 extern char *cache_get(const char *,unsigned int,unsigned int *,uint32 *);
--- a/log.c
+++ b/log.c
@@ -279,6 +279,12 @@ void log_stats(void)
   time_t cur = time(NULL);
   extern uint64 numqueries;
   extern uint64 cache_motion;
+
+  /* record cache stats */
+  /* James Raftery <james@now.ie> 6 Nov. 2003 */
+  extern uint64 cache_hit;
+  extern uint64 cache_miss;
+
   extern int uactive;
   extern int tactive;
 
@@ -290,6 +296,8 @@ void log_stats(void)
   number(numqueries); space();
   number(cache_motion); space();
   number(uactive); space();
-  number(tactive);
+  number(tactive); space();
+  number(cache_hit); space();
+  number(cache_miss);
   line();
 }