我知道我们可以从 MAT UI 获取线程详细信息和更多信息,但是有没有一种方法可以将这些堆栈(类似于线程转储)重定向到输出或运行任何 OQL 查询以获得相同的结果?
我们有相当大的 HeapDump(大约 16G),它显示了大约 500 个活动线程,并且通过 UI 遍历每个线程是一个乏味的过程。想知道是否有办法通过 MAT OQL 从堆转储中获取简化的线程转储。
谢谢
维斯瓦纳特
我知道我们可以从 MAT UI 获取线程详细信息和更多信息,但是有没有一种方法可以将这些堆栈(类似于线程转储)重定向到输出或运行任何 OQL 查询以获得相同的结果?
我们有相当大的 HeapDump(大约 16G),它显示了大约 500 个活动线程,并且通过 UI 遍历每个线程是一个乏味的过程。想知道是否有办法通过 MAT OQL 从堆转储中获取简化的线程转储。
谢谢
维斯瓦纳特
对于最近级别的 MAT,这应该可以:
SELECT u.Thread AS Thread, u.Frame.@text AS Frame FROM OBJECTS ( SELECT t AS Thread, ${snapshot}.getThreadStack(t.@objectId).@stackFrames AS Frame FROM java.lang.Thread t ) u
内部选择
SELECT t AS Thread, ${snapshot}.getThreadStack(t.@objectId).@stackFrames AS Frame FROM java.lang.Thread t
提取每个线程和堆栈帧数组。然后,外部选择使用相同的线程引用为每个堆栈帧展平该数组。
Thread |Frame
--------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.Thread [id=0x7b6a1e7f0]|at java.lang.Object.wait(J)V (Native Method)
java.lang.Thread [id=0x7b6a1e7f0]|at java.lang.Object.wait(JI)V (Unknown Source)
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.performCleanup()Z (ConnectionPool.java:305)
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.runCleanupUntilPoolIsEmpty()V (ConnectionPool.java:242)
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.access$000(Lcom/squareup/okhttp/ConnectionPool;)V (ConnectionPool.java:54)
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool$1.run()V (ConnectionPool.java:97)
--------------------------------------------------------------------------------------------------------------------------------------------------
您甚至可以使用另一个选择从每个帧中提取每个局部。
SELECT v.Thread AS Thread, v.Frame AS Frame, ${snapshot}.getObject(v.Objs) AS Local
FROM OBJECTS (
SELECT u.Thread AS Thread, u.Frame.@text AS Frame, u.Frame.@localObjectsIds AS Objs
FROM OBJECTS (
SELECT t AS Thread, ${snapshot}.getThreadStack(t.@objectId).@stackFrames AS Frame
FROM java.lang.Thread t
) u
) v
WHERE (v.Objs != null)
Thread |Frame |Local
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.performCleanup()Z (ConnectionPool.java:305) |java.util.ArrayList [id=0x7bb402eb8]
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.performCleanup()Z (ConnectionPool.java:305) |com.squareup.okhttp.ConnectionPool [id=0x6c556ccb0]
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.runCleanupUntilPoolIsEmpty()V (ConnectionPool.java:242) |com.squareup.okhttp.ConnectionPool [id=0x6c556ccb0]
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool.access$000(Lcom/squareup/okhttp/ConnectionPool;)V (ConnectionPool.java:54)|com.squareup.okhttp.ConnectionPool [id=0x6c556ccb0]
java.lang.Thread [id=0x7b6a1e7f0]|at com.squareup.okhttp.ConnectionPool$1.run()V (ConnectionPool.java:97) |com.squareup.okhttp.ConnectionPool$1 [id=0x6c556ccd8]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------