线程堆栈通过 MAT OQL 归档

Posted

技术标签:

【中文标题】线程堆栈通过 MAT OQL 归档【英文标题】:Thread Stack to file via MAT OQL 【发布时间】:2020-02-20 12:09:54 【问题描述】:

我知道我们可以通过 MAT UI 获取线程详细信息和更多信息,但是有没有一种方法可以将这些堆栈(类似于线程转储)重定向到输出或运行任何 OQL 查询以获取一样吗?

我们有相当大的 HeapDump(大约 16G),其中显示了大约 500 个活动线程,并且通过 UI 遍历每个线程是一个乏味的过程。想知道是否有办法通过 MAT OQL 从 Heap Dump 获取简化的线程转储。

谢谢

维什瓦纳特

【问题讨论】:

【参考方案1】:

对于最近的 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]
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

【讨论】:

以上是关于线程堆栈通过 MAT OQL 归档的主要内容,如果未能解决你的问题,请参考以下文章

dmarch.ini--dba手册

Eclipse MAT 的 ParseHeapDump 实用程序可以运行 OQL 吗?

Eclipse MAT OQL 某个包中的类列表

BATCH 文件:每年以特殊格式归档文件

如何为 xz 归档器设置默认参数?

归档: 2017/12