Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
126fd829
提交
126fd829
authored
1月 27, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The profiler tool can now process files with full thread dumps.
上级
dd38db03
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
110 行增加
和
51 行删除
+110
-51
changelog.html
h2/src/docsrc/html/changelog.html
+8
-3
Profiler.java
h2/src/main/org/h2/util/Profiler.java
+102
-48
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
126fd829
...
...
@@ -18,11 +18,16 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
MVStore mode: the CLOB and BLOB storage was re-implemented and is
<ul><li>
The profiler tool can now process files with full thread dumps.
</li><li>
MVStore mode: the CLOB and BLOB storage was re-implemented and is
now much faster than with the PageStore (which is still the default storage).
</li><li>
Various bugs in the MVStore storage and have been fixed.
</li><li>
MVStore mode: creating indexes is now much faster
(in many cases faster than with the default PageStore).
</li><li>
Various bugs in the MVStore storage and have been fixed,
including a bug in the R-tree implementation.
</li><li>
The method org.h2.expression.Function.getCost could throw a NullPointException.
</li><li>
Storing LOBs in separate files (outside of the database) is no longer supported for new databases.
</li><li>
Storing LOBs in separate files (outside of the main database file)
is no longer supported for new databases.
</li><li>
Lucene 2 is no longer supported.
</li><li>
Fix bug in calculating default MIN and MAX values for SEQUENCE.
</li></ul>
...
...
h2/src/main/org/h2/util/Profiler.java
浏览文件 @
126fd829
...
...
@@ -7,13 +7,16 @@
package
org
.
h2
.
util
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.LineNumberReader
;
import
java.io.OutputStream
;
import
java.io.Reader
;
import
java.io.StringReader
;
import
java.util.ArrayList
;
import
java.lang.instrument.Instrumentation
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
...
...
@@ -22,7 +25,7 @@ import java.util.Map;
/**
* A simple CPU profiling tool similar to java -Xrunhprof. It can be used
* in-process (to profile the current application) or as a standalone program
* (to profile a different process).
* (to profile a different process
, or files containing full thread dumps
).
*/
public
class
Profiler
implements
Runnable
{
...
...
@@ -37,11 +40,19 @@ public class Profiler implements Runnable {
private
int
pid
;
private
final
String
[]
ignoreLines
=
{};
private
final
String
[]
ignoreLines
=
(
"java,"
+
"sun,"
+
"com.sun.,"
+
"com.google.common.,"
+
"com.mongodb."
).
split
(
","
);
private
final
String
[]
ignorePackages
=
(
"java,"
+
"sun,"
+
"com.sun."
"com.sun.,"
+
"com.google.common.,"
+
"com.mongodb."
).
split
(
","
);
private
final
String
[]
ignoreThreads
=
(
"java.lang.Object.wait,"
+
...
...
@@ -49,6 +60,7 @@ public class Profiler implements Runnable {
"java.lang.Thread.getThreads,"
+
"java.lang.Thread.sleep,"
+
"java.lang.UNIXProcess.waitForProcessExit,"
+
"java.net.PlainDatagramSocketImpl.receive0,"
+
"java.net.PlainSocketImpl.accept,"
+
"java.net.PlainSocketImpl.socketAccept,"
+
"java.net.SocketInputStream.socketRead,"
+
...
...
@@ -72,6 +84,7 @@ public class Profiler implements Runnable {
private
Thread
thread
;
private
long
start
;
private
long
time
;
private
int
threadDumps
;
/**
* This method is called when the agent is installed.
...
...
@@ -106,14 +119,15 @@ public class Profiler implements Runnable {
private
void
run
(
String
...
args
)
{
if
(
args
.
length
==
0
)
{
System
.
out
.
println
(
"Show profiling data"
);
System
.
out
.
println
(
"Usage: java "
+
getClass
().
getName
()
+
" <pid>"
);
System
.
out
.
println
(
"Usage: java "
+
getClass
().
getName
()
+
" <pid>
| <stackTraceFileNames>
"
);
System
.
out
.
println
(
"Processes:"
);
String
processes
=
exec
(
"jps"
,
"-l"
);
System
.
out
.
println
(
processes
);
return
;
}
pid
=
Integer
.
parseInt
(
args
[
0
]);
start
=
System
.
currentTimeMillis
();
if
(
args
[
0
].
matches
(
"\\d+"
))
{
pid
=
Integer
.
parseInt
(
args
[
0
]);
long
last
=
0
;
while
(
true
)
{
tick
();
...
...
@@ -125,6 +139,31 @@ public class Profiler implements Runnable {
}
}
}
try
{
for
(
String
file
:
args
)
{
Reader
reader
;
LineNumberReader
r
;
reader
=
new
InputStreamReader
(
new
FileInputStream
(
file
),
"CP1252"
);
r
=
new
LineNumberReader
(
reader
);
while
(
true
)
{
String
line
=
r
.
readLine
();
if
(
line
==
null
)
{
break
;
}
else
if
(
line
.
startsWith
(
"Full thread dump"
))
{
threadDumps
++;
}
}
reader
.
close
();
reader
=
new
InputStreamReader
(
new
FileInputStream
(
file
),
"CP1252"
);
r
=
new
LineNumberReader
(
reader
);
processList
(
readStackTrace
(
r
));
reader
.
close
();
}
System
.
out
.
println
(
getTopTraces
(
3
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
static
List
<
Object
[]>
getRunnableStackTraces
()
{
ArrayList
<
Object
[]>
list
=
new
ArrayList
<
Object
[]>();
...
...
@@ -144,10 +183,17 @@ public class Profiler implements Runnable {
}
private
static
List
<
Object
[]>
readRunnableStackTraces
(
int
pid
)
{
ArrayList
<
Object
[]>
list
=
new
ArrayList
<
Object
[]>();
try
{
String
jstack
=
exec
(
"jstack"
,
""
+
pid
);
LineNumberReader
r
=
new
LineNumberReader
(
new
StringReader
(
jstack
));
return
readStackTrace
(
r
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
static
List
<
Object
[]>
readStackTrace
(
LineNumberReader
r
)
throws
IOException
{
ArrayList
<
Object
[]>
list
=
new
ArrayList
<
Object
[]>();
while
(
true
)
{
String
line
=
r
.
readLine
();
if
(
line
==
null
)
{
...
...
@@ -187,9 +233,6 @@ public class Profiler implements Runnable {
}
}
return
list
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
private
static
String
exec
(
String
...
args
)
{
...
...
@@ -292,6 +335,11 @@ public class Profiler implements Runnable {
}
else
{
list
=
getRunnableStackTraces
();
}
threadDumps
++;
processList
(
list
);
}
private
void
processList
(
List
<
Object
[]>
list
)
{
for
(
Object
[]
dump
:
list
)
{
if
(
startsWithAny
(
dump
[
0
].
toString
(),
ignoreThreads
))
{
continue
;
...
...
@@ -377,8 +425,14 @@ public class Profiler implements Runnable {
private
String
getTopTraces
(
int
count
)
{
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"Profiler: top "
).
append
(
count
).
append
(
" stack trace(s) of "
).
append
(
time
).
append
(
" ms:"
).
append
(
LINE_SEPARATOR
);
buff
.
append
(
"Profiler: top "
).
append
(
count
).
append
(
" stack trace(s) of "
);
if
(
time
>
0
)
{
buff
.
append
(
" of "
).
append
(
time
).
append
(
" ms"
);
}
if
(
threadDumps
>
0
)
{
buff
.
append
(
" of "
).
append
(
threadDumps
).
append
(
" thread dumps"
);
}
buff
.
append
(
":"
).
append
(
LINE_SEPARATOR
);
if
(
counts
.
size
()
==
0
)
{
buff
.
append
(
"(none)"
).
append
(
LINE_SEPARATOR
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论