Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7a2fba10
提交
7a2fba10
authored
9月 03, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change order for checkstyle.
上级
d70793f2
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
48 行删除
+50
-48
QueryStatisticsData.java
h2/src/main/org/h2/engine/QueryStatisticsData.java
+50
-48
没有找到文件。
h2/src/main/org/h2/engine/QueryStatisticsData.java
浏览文件 @
7a2fba10
...
@@ -22,40 +22,24 @@ public class QueryStatisticsData {
...
@@ -22,40 +22,24 @@ public class QueryStatisticsData {
private
static
final
int
MAX_QUERY_ENTRIES
=
100
;
private
static
final
int
MAX_QUERY_ENTRIES
=
100
;
public
static
final
class
QueryEntry
{
private
static
final
Comparator
<
QueryEntry
>
QUERY_ENTRY_COMPARATOR
=
new
Comparator
<
QueryEntry
>()
{
public
String
sqlStatement
;
@Override
public
int
compare
(
QueryEntry
o1
,
QueryEntry
o2
)
{
public
long
lastUpdateTime
;
return
(
int
)
Math
.
signum
(
o1
.
lastUpdateTime
-
o2
.
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
);
}
}
};
public
double
getRowCountStandardDeviation
()
{
private
final
HashMap
<
String
,
QueryEntry
>
map
=
new
HashMap
<
String
,
QueryEntry
>();
// population standard deviation
return
Math
.
sqrt
(
rowCountM2
/
count
);
}
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.
* Update query statistics.
*
*
...
@@ -68,15 +52,12 @@ public class QueryStatisticsData {
...
@@ -68,15 +52,12 @@ public class QueryStatisticsData {
if
(
entry
==
null
)
{
if
(
entry
==
null
)
{
entry
=
new
QueryEntry
();
entry
=
new
QueryEntry
();
entry
.
sqlStatement
=
sqlStatement
;
entry
.
sqlStatement
=
sqlStatement
;
entry
.
count
=
1
;
entry
.
executionTimeMin
=
executionTime
;
entry
.
executionTimeMin
=
executionTime
;
entry
.
executionTimeMax
=
executionTime
;
entry
.
executionTimeMax
=
executionTime
;
entry
.
rowCountMin
=
rowCount
;
entry
.
rowCountMin
=
rowCount
;
entry
.
rowCountMax
=
rowCount
;
entry
.
rowCountMax
=
rowCount
;
entry
.
executionTimeMean
=
executionTime
;
entry
.
executionTimeMean
=
executionTime
;
entry
.
executionTimeM2
=
0
;
entry
.
rowCountMean
=
rowCount
;
entry
.
rowCountMean
=
rowCount
;
entry
.
rowCountM2
=
0
;
map
.
put
(
sqlStatement
,
entry
);
map
.
put
(
sqlStatement
,
entry
);
}
else
{
}
else
{
entry
.
count
++;
entry
.
count
++;
...
@@ -117,19 +98,40 @@ public class QueryStatisticsData {
...
@@ -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
* The collected statistics for one query.
ArrayList
<
QueryEntry
>
list
=
new
ArrayList
<
QueryEntry
>();
*/
list
.
addAll
(
map
.
values
());
public
static
final
class
QueryEntry
{
// only return the newest 100 entries
Collections
.
sort
(
list
,
QUERY_ENTRY_COMPARATOR
);
public
String
sqlStatement
;
return
list
.
subList
(
0
,
Math
.
min
(
list
.
size
(),
MAX_QUERY_ENTRIES
));
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
>()
{
public
double
getRowCountStandardDeviation
()
{
@Override
// population standard deviation
public
int
compare
(
QueryEntry
o1
,
QueryEntry
o2
)
{
return
Math
.
sqrt
(
rowCountM2
/
count
);
return
(
int
)
Math
.
signum
(
o1
.
lastUpdateTime
-
o2
.
lastUpdateTime
);
}
}
};
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论