.net-4.0garbage-collectionwindbgsossosex

Number of GC perfomred for various generations from a dump file


Is there anyway to get information about how many Garbage collection been performed for different generations from a dump file. When I try to run some psscor4 commands I get following.

0:003> !GCUsage
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.
Error: Requesting GC Heap data
0:003> !CLRUsage
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.
Error: Requesting GC Heap data

I can get output from eehpeap though, but it does not give me what I am looking for.

0:003> !EEHeap -gc
Number of GC Heaps: 1
generation 0 starts at 0x0000000002c81030
generation 1 starts at 0x0000000002c81018
generation 2 starts at 0x0000000002c81000
ephemeral segment allocation context: none
 segment     begin allocated  size
0000000002c80000  0000000002c81000  0000000002c87fe8  0x6fe8(28648)
Large object heap starts at 0x0000000012c81000
 segment     begin allocated  size
0000000012c80000  0000000012c81000  0000000012c9e358  0x1d358(119640)
Total Size:              Size: 0x24340 (148288) bytes.
------------------------------
GC Heap Size:            Size: 0x24340 (148288) bytes.

Solution

  • Dumps

    You can see the number of garbage collections in performance monitor. However, the way performance counters work makes me believe that this information is not available in a dump file and probably even not available during live debugging.

    Think of Debug.WriteLine(): once the text was written to the debug output, it is gone. If you didn't have DebugView running at the time, the information is lost. And that's good, otherwise it would look like a memory leak.

    Performance counters (as I understand them) work in a similar fashion. Various "pings" are sent out for someone else (the performance monitor) to be recorded. If noone does, the ping with all its information is gone.

    Live debugging

    As already mentioned, you can try performance monitor. If you prefer WinDbg, you can use sxe clrn to see garbage collections happen.

    PSSCOR

    The commands you mentioned, do not show information about garbage collection count:

    0:016> !gcusage
    Number of GC Heaps: 1
    ------------------------------
    GC Heap Size          0x36d498(3,593,368)
    Total Commit Size  0000000000384000 (3 MB)
    Total Reserved Size  0000000017c7c000 (380 MB)
    
    0:016> !clrusage
    Number of GC Heaps: 1
    ------------------------------
    GC Heap Size          0x36d498(3,593,368)
    Total Commit Size  0000000000384000 (3 MB)
    Total Reserved Size  0000000017c7c000 (380 MB)
    

    Note: I'm using PSSCOR2 here, since I have the same .NET 4.5 issue on this machine. But I expect the output of PSSCOR4 to be similar.