Visual studio 获取visual studio ultimate“;“调试托管内存”;windbg的输出

Visual studio 获取visual studio ultimate“;“调试托管内存”;windbg的输出,visual-studio,windbg,Visual Studio,Windbg,是否可以在WINDBG中获取堆上托管对象的摘要信息,该信息类似于Visual Studio Ultimate的“调试托管内存”选项提供的摘要 我可以获得一些信息,但这是一个个案的基础上,是相当乏味的。 是否有一个宏或一组命令可以使用WINDBG生成类似的输出 Visual Studio似乎有一个简洁的小例程,它收集所有根并显示根对象类及其总内存的摘要。这些将为您提供特定类型的托管内存、堆摘要和堆消耗,以防您试图在堆上查找字符串: !EEHeap !DumpHeap -stat !DumpHea

是否可以在WINDBG中获取堆上托管对象的摘要信息,该信息类似于Visual Studio Ultimate的“调试托管内存”选项提供的摘要

我可以获得一些信息,但这是一个个案的基础上,是相当乏味的。 是否有一个宏或一组命令可以使用WINDBG生成类似的输出


Visual Studio似乎有一个简洁的小例程,它收集所有根并显示根对象类及其总内存的摘要。

这些将为您提供特定类型的托管内存、堆摘要和堆消耗,以防您试图在堆上查找字符串:

!EEHeap
!DumpHeap -stat 
!DumpHeap -strings 
!DumpHeap -Type <TypeSpec> 
有关更多信息,请参阅。
sosex是另一个扩展,但我没有用它来调试泄漏。与Windbg IMHO相比,CLRProfiler和Visual Studio Standalone Profiler是调试这些问题的最佳工具。

与任何.NET问题一样,您首先需要SOS扩展

.loadby sos clr; .loadby sos mscorwks
然后,您可以使用

!dumpheap -stat; * Statistics output, good if you don't know what you're looking for
!dumpheap -type <SubstringOfClass>; * If you know what type you're after
!dumpheap -mt <MethodTable>; * If the class substring is not unique enough
示例演练:

0:005> !dumpheap -stat
Statistics:
              MT    Count    TotalSize Class Name
000007fef2611ec8        1           24 System.Collections.Generic.ObjectEqualityComparer`1[[System.Runtime.Serialization.MemberHolder, mscorlib]]
...
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
...
000007fef25fa690      396       117910 System.Byte[]
000007fef25a4458     1570       227560 System.Object[]
000007fef25f6508     3300       234762 System.String
Total 17883 objects

0:005> !dumpheap -stat -type Handler
Statistics:
              MT    Count    TotalSize Class Name
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
000007fef26228b0        1           64 System.BaseConfigHandler+CreateNodeCallback
000007fef26227f8        1           64 System.BaseConfigHandler+ErrorCallback
Total 3 objects

0:005> !dumpheap -mt 000007fef2622968
         Address               MT     Size
0000000002594848 000007fef2622968       64     

Statistics:
              MT    Count    TotalSize Class Name
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
Total 1 objects

0:005> !objsize 0000000002594848 
sizeof(0000000002594848) = 168728 (0x29318) bytes (System.BaseConfigHandler+CreateAttributeCallback)

0:005> !gcroot 0000000002594848 
Found 0 unique roots (run '!GCRoot -all' to see all roots).

0:005> !gcroot -all 0000000002594848 
Found 0 roots.
因此,这个对象似乎没有更多的引用,将在下一次GC期间被垃圾收集

0:001> !dso
OS Thread Id: 0xb2c (1)
RSP/REG          Object           Name
00000000024B0000 00000000024b1048 System.Exception
相关的:
!gcroot <address>
~*e !dso
0:005> !dumpheap -stat
Statistics:
              MT    Count    TotalSize Class Name
000007fef2611ec8        1           24 System.Collections.Generic.ObjectEqualityComparer`1[[System.Runtime.Serialization.MemberHolder, mscorlib]]
...
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
...
000007fef25fa690      396       117910 System.Byte[]
000007fef25a4458     1570       227560 System.Object[]
000007fef25f6508     3300       234762 System.String
Total 17883 objects

0:005> !dumpheap -stat -type Handler
Statistics:
              MT    Count    TotalSize Class Name
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
000007fef26228b0        1           64 System.BaseConfigHandler+CreateNodeCallback
000007fef26227f8        1           64 System.BaseConfigHandler+ErrorCallback
Total 3 objects

0:005> !dumpheap -mt 000007fef2622968
         Address               MT     Size
0000000002594848 000007fef2622968       64     

Statistics:
              MT    Count    TotalSize Class Name
000007fef2622968        1           64 System.BaseConfigHandler+CreateAttributeCallback
Total 1 objects

0:005> !objsize 0000000002594848 
sizeof(0000000002594848) = 168728 (0x29318) bytes (System.BaseConfigHandler+CreateAttributeCallback)

0:005> !gcroot 0000000002594848 
Found 0 unique roots (run '!GCRoot -all' to see all roots).

0:005> !gcroot -all 0000000002594848 
Found 0 roots.
0:001> !dso
OS Thread Id: 0xb2c (1)
RSP/REG          Object           Name
00000000024B0000 00000000024b1048 System.Exception