1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.io.hfile;
21
22 import java.util.concurrent.atomic.AtomicLong;
23
24
25
26
27 public class CacheStats {
28
29 private final AtomicLong hitCount = new AtomicLong(0);
30
31
32
33
34
35
36 private final AtomicLong hitCachingCount = new AtomicLong(0);
37
38 private final AtomicLong missCount = new AtomicLong(0);
39
40
41
42
43 private final AtomicLong missCachingCount = new AtomicLong(0);
44
45 private final AtomicLong evictionCount = new AtomicLong(0);
46
47 private final AtomicLong evictedBlockCount = new AtomicLong(0);
48
49 public void miss(boolean caching) {
50 missCount.incrementAndGet();
51 if (caching) missCachingCount.incrementAndGet();
52 }
53
54 public void hit(boolean caching) {
55 hitCount.incrementAndGet();
56 if (caching) hitCachingCount.incrementAndGet();
57 }
58
59 public void evict() {
60 evictionCount.incrementAndGet();
61 }
62
63 public void evicted() {
64 evictedBlockCount.incrementAndGet();
65 }
66
67 public long getRequestCount() {
68 return getHitCount() + getMissCount();
69 }
70
71 public long getRequestCachingCount() {
72 return getHitCachingCount() + getMissCachingCount();
73 }
74
75 public long getMissCount() {
76 return missCount.get();
77 }
78
79 public long getMissCachingCount() {
80 return missCachingCount.get();
81 }
82
83 public long getHitCount() {
84 return hitCount.get();
85 }
86
87 public long getHitCachingCount() {
88 return hitCachingCount.get();
89 }
90
91 public long getEvictionCount() {
92 return evictionCount.get();
93 }
94
95 public long getEvictedCount() {
96 return evictedBlockCount.get();
97 }
98
99 public double getHitRatio() {
100 return ((float)getHitCount()/(float)getRequestCount());
101 }
102
103 public double getHitCachingRatio() {
104 return ((float)getHitCachingCount()/(float)getRequestCachingCount());
105 }
106
107 public double getMissRatio() {
108 return ((float)getMissCount()/(float)getRequestCount());
109 }
110
111 public double getMissCachingRatio() {
112 return ((float)getMissCachingCount()/(float)getRequestCachingCount());
113 }
114
115 public double evictedPerEviction() {
116 return ((float)getEvictedCount()/(float)getEvictionCount());
117 }
118 }