public void SegmentEnumeration() { // Simply test that we can enumerate the heap. using DataTarget dt = TestTargets.Types.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; ClrObject[] objs = heap.EnumerateObjects().ToArray(); // Enumerating each segment and then each object on each segment should produce // the same enumeration as ClrHeap.EnumerateObjects(). int index = 0; foreach (ClrSegment seg in heap.Segments) { foreach (ClrObject obj in seg.EnumerateObjects()) { Assert.Equal(objs[index], obj); index++; } } ClrSegment large = heap.Segments.Single(s => s.IsLargeObjectSegment); large.EnumerateObjects().ToArray(); Assert.Equal(objs.Length, index); }
/// <summary> /// Gets the LOH size and the object summary in the LOH /// </summary> /// <param name="minTotalSize">The min size that we will be filtering on.</param> /// <returns>List with ClrType's Name, Count of Object of ClrType and total size of that type</returns> private IEnumerable <(string type, int count, long size)> GetLOHStats() { ClrSegment lohSegment = Runtime.Heap.Segments.Where(s => s.IsLargeObjectSegment).First(); IEnumerable <ClrObject> objects = lohSegment.EnumerateObjects(); var stats = GetStats(objects); return(stats.Select(s => (type: s.type.Name, count: s.objects.Count(), s.size))); }
private static void WalkSegment(ClrSegment seg) { foreach (ClrObject obj in seg.EnumerateObjects().Take(2048)) { foreach (ClrReference reference in obj.EnumerateReferencesWithFields(carefully: false, considerDependantHandles: true)) { _ = reference.Object; } } }