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