!DumpHeap - 可以禁用 GC 警告吗?

!DumpHeap - possible to disable GC warning?

我有一个来自 NT 服务的完整进程转储(使用 C#/.NET 4.5.2 实现),它处于 GC 周期的中间。当我将它加载到 WinDbg 并尝试 运行 !DumpHeap -stat(或 DumpHeap 的任何其他变体)时,我收到此警告:

The garbage collector data structures are not in a valid state for traversal. It is either in the "plan phase," where objects are being moved around, or we are at the initialization or shutdown of the gc heap. Commands related to displaying, finding or traversing objects as well as gc heap segments may not work properly. !dumpheap and !verifyheap may incorrectly complain of heap consistency errors.

不幸的是,我无法(轻松地)在 GC 之外获得干净的内存转储(我显然不知道它何时发生并且我需要一些可管理大小的转储 - 我正在查看的进程泄漏内存和有时会达到 18 GB;这太大了,以至于大多数堆查找在 WinDbg 中需要超过 40 分钟。)

即使我使用 -short 参数仅生成对象地址(将它们输入到 WinDbg 宏中),也会出现此警告消息 - 不幸的是,警告消息中的文字作为输入参数传递给宏和宏炸毁。 (该宏是 this question 的变体,我正在尝试 运行 !GCRoot 大量对象实例。)

有没有办法在 WinDbg 中禁用此警告消息? (DumpHeap 是 SOS 的一部分,所以我想如果可能的话,需要在那里禁用它。)

Edit:为了清楚起见,我从 DumpHeap 和其他命令(看起来基本一致)得到了有用的输出,只是所有输出都以以上警告,即使使用 -short。这意味着我无法将输出输入其他命令。

你的问题

我知道很遗憾 -short 输出包含该消息。恕我直言,无法禁用消息。

您可以使用 pykd (Codeplex) to filter the text. You'd need the dbgCommand() function to issue the !dumpheap command. You'll get back a string with the output of the command and you can then filter the text. Next you could push the text back to the debugger with dprint().

其他想法

  1. 也许你想试试.

  2. 加快速度:

    • 有一个 !bhi 命令来建立堆索引。
    • netext有一个!windex命令来建立堆索引。它甚至有一个类似于 !dumpheap 的命令,可以以 .foreach 的方式使用(来自网站):

      .foreach({$addr} {!windex -short -type *.HttpRequest}){!wselect _url.m_String from {$addr} }
      
  3. PyKd:当你在做的时候,你也可以重写 Python 中的 .foreach 循环并在 [=55= 中做 !do 部分] 同样,允许您根据对象的内容等过滤对象,因此您可以通过使用更直观的脚本语言来节省一些时间。