1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.io.hfile.bucket;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.io.hfile.CacheStats;
23 import org.apache.hadoop.hbase.util.Counter;
24 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
25
26
27
28
29 @InterfaceAudience.Private
30 public class BucketCacheStats extends CacheStats {
31 private final Counter ioHitCount = new Counter(0);
32 private final Counter ioHitTime = new Counter(0);
33 private final static int nanoTime = 1000000;
34 private long lastLogTime = EnvironmentEdgeManager.currentTime();
35
36 BucketCacheStats() {
37 super("BucketCache");
38 }
39
40 @Override
41 public String toString() {
42 return super.toString() + ", ioHitsPerSecond=" + getIOHitsPerSecond() +
43 ", ioTimePerHit=" + getIOTimePerHit();
44 }
45
46 public void ioHit(long time) {
47 ioHitCount.increment();
48 ioHitTime.add(time);
49 }
50
51 public long getIOHitsPerSecond() {
52 long now = EnvironmentEdgeManager.currentTime();
53 long took = (now - lastLogTime) / 1000;
54 lastLogTime = now;
55 return took == 0? 0: ioHitCount.get() / took;
56 }
57
58 public double getIOTimePerHit() {
59 long time = ioHitTime.get() / nanoTime;
60 long count = ioHitCount.get();
61 return ((float) time / (float) count);
62 }
63
64 public void reset() {
65 ioHitCount.set(0);
66 ioHitTime.set(0);
67 }
68 }