This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
/
Statistics.java
110 lines (102 loc) · 3.71 KB
/
Statistics.java
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. See accompanying LICENSE file.
*/
package com.yahoo.omid;
//import java.io.DataOutputStream;
//import java.io.IOException;
import java.util.Map;
import java.util.EnumMap;
/**
* To collect statistics
* @author maysam
*
*/
public class Statistics {
public enum Tag {
VSN_PER_HBASE_GET,//number of returned version per hbase get operation
VSN_PER_CLIENT_GET,//number of returned version per client get operation
GET_PER_CLIENT_GET,//number of hbase get performed per client get operation
COMMIT,//number of commits
REINCARNATION,//number of reincarnations
ASKTSO,//number of queries sent to tso
EMPTY_GET,//number of hbase get that return nothing
dummy
}
static class History {
public int cnt;
public long total;
}
static Map<Tag, History> histories = new EnumMap<Tag, History>(Tag.class);
static Map<Tag, History> partialChanges = new EnumMap<Tag, History>(Tag.class);
static protected History getHistory(Tag tag, Map<Tag, History> map) {
History history = map.get(tag);
if (history == null) {
history = new History();
map.put(tag, history);
}
return history;
}
static public void partialReport(Tag tag, int value) {
synchronized (histories) {
History tmpHistory = getHistory(tag, partialChanges);
tmpHistory.total += value;
}
}
static public void partialReportOver(Tag tag) {
synchronized (histories) {
History tmpHistory = getHistory(tag, partialChanges);
if (tmpHistory.total == 0)
return;
History history = getHistory(tag, histories);
history.cnt ++;
history.total += tmpHistory.total;
tmpHistory.total = 0;
}
}
static public void fullReport(Tag tag, int value) {
synchronized (histories) {
if (value == 0)
return;
History history = getHistory(tag, histories);
history.cnt ++;
history.total += value;
}
}
static long lastReportTime = System.currentTimeMillis();
static final long reportInterval = 2000;
static public boolean skipReport() {
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - lastReportTime > reportInterval) {
lastReportTime = currentTimeMillis;
return false;
}
return true;
}
static public void println() {
synchronized (histories) {
if (skipReport())
return;
System.out.print("Statistics: ");
for (Map.Entry<Tag, History> entry : histories.entrySet()) {
Tag tag = entry.getKey();
History history = entry.getValue();
System.out.print(tag + "Cnt " + history.cnt + " ");
System.out.print(tag + "Sum " + history.total + " ");
System.out.print(tag + "Avg " + (float) history.total / history.cnt + " ");
}
System.out.println();
}
}
}