我知道我们有办法从MAT UI获取线程详细信息和更多信息,但有没有办法让这些堆栈(类似于线程转储)重定向到输出或运行任何OQL查询来获得相同的信息?
我们有相当大的HeapDump (大约16G),它显示了大约500个活动线程,并且遍历每一个via UI都是一个乏味的过程。我想知道是否有一种方法可以通过MAT OQL从堆转储中获得简化的线程转储。
谢谢
维什瓦纳特
发布于 2020-10-02 23:53:10
对于最近的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提取每个线程和堆栈帧的数组。然后,外部select使用与其每个堆栈帧相同的线程引用来展平该数组。
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从每个帧中提取每个局部。
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]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------https://stackoverflow.com/questions/60319611
复制相似问题