提交 7a2fba10 authored 作者: Thomas Mueller's avatar Thomas Mueller

Change order for checkstyle.

上级 d70793f2
......@@ -22,40 +22,24 @@ public class QueryStatisticsData {
private static final int MAX_QUERY_ENTRIES = 100;
public static final class QueryEntry {
public String sqlStatement;
public long lastUpdateTime;
public int count;
public long executionTimeMin;
public long executionTimeMax;
public long executionTimeCumulative;
public int rowCountMin;
public int rowCountMax;
public long rowCountCumulative;
// Using Welford's method, see also
// http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// http://www.johndcook.com/standard_deviation.html
public double executionTimeMean;
public double executionTimeM2;
public double rowCountMean;
public double rowCountM2;
public double getExecutionTimeStandardDeviation() {
// population standard deviation
return Math.sqrt(executionTimeM2 / count);
private static final Comparator<QueryEntry> QUERY_ENTRY_COMPARATOR = new Comparator<QueryEntry>() {
@Override
public int compare(QueryEntry o1, QueryEntry o2) {
return (int) Math.signum(o1.lastUpdateTime - o2.lastUpdateTime);
}
};
public double getRowCountStandardDeviation() {
// population standard deviation
return Math.sqrt(rowCountM2 / count);
}
private final HashMap<String, QueryEntry> map = new HashMap<String, QueryEntry>();
public synchronized List<QueryEntry> getQueries() {
// return a copy of the map so we don't have to worry about external synchronization
ArrayList<QueryEntry> list = new ArrayList<QueryEntry>();
list.addAll(map.values());
// only return the newest 100 entries
Collections.sort(list, QUERY_ENTRY_COMPARATOR);
return list.subList(0, Math.min(list.size(), MAX_QUERY_ENTRIES));
}
private final HashMap<String, QueryEntry> map = new HashMap<String, QueryEntry>();
/**
* Update query statistics.
*
......@@ -68,15 +52,12 @@ public class QueryStatisticsData {
if (entry == null) {
entry = new QueryEntry();
entry.sqlStatement = sqlStatement;
entry.count = 1;
entry.executionTimeMin = executionTime;
entry.executionTimeMax = executionTime;
entry.rowCountMin = rowCount;
entry.rowCountMax = rowCount;
entry.executionTimeMean = executionTime;
entry.executionTimeM2 = 0;
entry.rowCountMean = rowCount;
entry.rowCountM2 = 0;
map.put(sqlStatement, entry);
} else {
entry.count++;
......@@ -117,19 +98,40 @@ public class QueryStatisticsData {
}
}
public synchronized List<QueryEntry> getQueries() {
// return a copy of the map so we don't have to worry about external synchronization
ArrayList<QueryEntry> list = new ArrayList<QueryEntry>();
list.addAll(map.values());
// only return the newest 100 entries
Collections.sort(list, QUERY_ENTRY_COMPARATOR);
return list.subList(0, Math.min(list.size(), MAX_QUERY_ENTRIES));
/**
* The collected statistics for one query.
*/
public static final class QueryEntry {
public String sqlStatement;
public int count = 1;
public long lastUpdateTime;
public long executionTimeMin;
public long executionTimeMax;
public long executionTimeCumulative;
public int rowCountMin;
public int rowCountMax;
public long rowCountCumulative;
// Using Welford's method, see also
// http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
// http://www.johndcook.com/standard_deviation.html
public double executionTimeMean;
public double executionTimeM2;
public double rowCountMean;
public double rowCountM2;
public double getExecutionTimeStandardDeviation() {
// population standard deviation
return Math.sqrt(executionTimeM2 / count);
}
private static final Comparator<QueryEntry> QUERY_ENTRY_COMPARATOR = new Comparator<QueryEntry>() {
@Override
public int compare(QueryEntry o1, QueryEntry o2) {
return (int) Math.signum(o1.lastUpdateTime - o2.lastUpdateTime);
public double getRowCountStandardDeviation() {
// population standard deviation
return Math.sqrt(rowCountM2 / count);
}
};
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论