SqlFrequency.java
1.82 KB
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
package io.mycat.statistic.stat;
import java.util.concurrent.atomic.AtomicLong;
public class SqlFrequency implements Comparable<SqlFrequency>{
private String sql;
private AtomicLong count = new AtomicLong(0);
private long lastTime = 0;
private long executeTime = 0;
private long allExecuteTime = 0;
private long maxTime = 0;
private long avgTime = 0;
private long minTime = 0;
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public long getCount() {
return this.count.get();
}
public void incCount() {
this.count.getAndIncrement();
}
public long getLastTime() {
return lastTime;
}
public void setLastTime(long lastTime) {
this.lastTime = lastTime;
}
public long getExecuteTime() {
return executeTime;
}
public long getMaxTime() {
return maxTime;
}
public long getMinTime() {
return minTime;
}
public long getAvgTime() {
return avgTime;
}
public void setExecuteTime(long execTime) {
if (execTime > this.maxTime) {
this.maxTime = execTime;
}
if (this.minTime == 0) {
this.minTime = execTime;
}
if (execTime > 0
&& execTime < this.minTime) {
this.minTime = execTime;
}
this.allExecuteTime+=execTime;
if (count.get() > 0) {
this.avgTime = this.allExecuteTime / this.count.get();
}
this.executeTime = execTime;
}
@Override
public int compareTo(SqlFrequency o) {
long para = o.count.get() - count.get();
long para2 = o.lastTime - lastTime;
return para == 0L ? (int)(para2 == 0L ? o.allExecuteTime - allExecuteTime : para2) : (int)para ;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof SqlFrequency) {
return this.compareTo((SqlFrequency)obj) == 0;
} else {
return super.equals(obj);
}
}
}