This is a very small change to address https://github.com/dotnet/diagnostics/issues/3963
Few questions:
1) Should I add tests for this?
2) I've asked about GCGeneration custom type that is a clone of
Generation "official" type in that issue. It is a part of dumpgen
command which itself, after this change, kinda loses it's meaning. I
think the way forward is just to either remove dumpgen command or leave
it as a proxy for dumpheap.
[Option(Name = "-thinlock")]
public bool ThinLock { get; set; }
+ [Option(Name = "-gen")]
+ public string Generation { get; set; }
+
[Argument(Help = "Optional memory ranges in the form of: [Start [End]]")]
public string[] MemoryRange { get; set; }
MethodTable = Runtime.Heap.StringType.MethodTable;
}
+ if (!string.IsNullOrWhiteSpace(Generation))
+ {
+ Generation generation = Generation.ToLowerInvariant() switch
+ {
+ "gen0" => Diagnostics.Runtime.Generation.Generation0,
+ "gen1" => Diagnostics.Runtime.Generation.Generation1,
+ "gen2" => Diagnostics.Runtime.Generation.Generation2,
+ "loh" or "large" => Diagnostics.Runtime.Generation.Large,
+ "poh" or "pinned" => Diagnostics.Runtime.Generation.Pinned,
+ "foh" or "frozen" => Diagnostics.Runtime.Generation.Frozen,
+ _ => throw new ArgumentException($"Unknown generation: {Generation}. Only gen0, gen1, gen2, loh (large), poh (pinned) and foh (frozen) are supported")
+ };
+
+ FilteredHeap.Generation = generation;
+ }
+
FilteredHeap.SortSegments = (seg) => seg.OrderBy(seg => seg.Start);
}
}
/// </summary>
public ulong MaximumObjectSize { get; set; }
+ /// <summary>
+ /// Only enumerate object from this generation
+ /// </summary>
+ public Generation? Generation { get; set; }
+
/// <summary>
/// The order in which to enumerate segments. This also applies to object enumeration.
/// </summary>
objs = segment.EnumerateObjects(carefully: true);
}
+ if (Generation is Generation generation)
+ {
+ objs = objs.Where(obj => segment.GetGeneration(obj) == generation);
+ }
+
foreach (ClrObject obj in objs)
{
cancellation.ThrowIfCancellationRequested();
VERIFY:\s+MT\s+Count\s+TotalSize\s+Class\s+Name\s+
VERIFY:\s+<HEXVAL>\s+<DECVAL>\s+<DECVAL>\s+System.Byte\[\]\s+
+SOSCOMMAND:DumpHeap -stat -gen poh
+VERIFY:\s*Statistics:\s+
+VERIFY:\s+MT\s+Count\s+TotalSize\s+Class\s+Name\s+
+VERIFY:\s+<HEXVAL>\s+<DECVAL>\s+<DECVAL>\s+System.Byte\[\]\s+
+
SOSCOMMAND:EEHeap
VERIFY:\s*Loader Heap:\s+
VERIFY:\s+System Domain:\s+<HEXVAL>\s+
VERIFY:\s+MT\s+Count\s+TotalSize\s+Class\s+Name\s+
VERIFY:\s+<HEXVAL>\s+<DECVAL>\s+<DECVAL>\s+GCWhere\s+
+SOSCOMMAND:DumpHeap -stat -gen gen0
+VERIFY:\s*Statistics:\s+
+VERIFY:\s+MT\s+Count\s+TotalSize\s+Class\s+Name\s+
+VERIFY:\s+<HEXVAL>\s+<DECVAL>\s+<DECVAL>\s+GCWhere\s+
+
+IFDEF:WINDOWS
+SOSCOMMAND:DumpHeap -stat -gen xxx
+VERIFY:\s*System\.ArgumentException: Unknown generation: xxx\. Only gen0, gen1, gen2, loh \(large\), poh \(pinned\) and foh \(frozen\) are supported\s+
+ENDIF:WINDOWS
+
IFDEF:WINDOWS
SOSCOMMAND:DumpHeap -strings
VERIFY:\s+<HEXVAL>\s+<HEXVAL>\s+<DECVAL>\s+