HackedBrain.ScriptCs.ClrMd.ClrMdPack.DumpObjects C# (CSharp) Method

DumpObjects() public method

public DumpObjects ( string typeName ) : void
typeName string
return void
		public void DumpObjects(string typeName)
		{
			ClrHeap clrHeap = this.ClrRuntime.GetHeap();
			
			IEnumerable<ulong> objectIds = clrHeap.EnumerateObjects();

			var objects = (from objectId in objectIds
						  let type = clrHeap.GetObjectType(objectId)
						  let heapGeneration = clrHeap.GetGeneration(objectId)
						  let heapSize = (long)type.GetSize(objectId)
						  where type.Name.StartsWith(typeName)
						  select new
						  {
							  ObjectId = objectId,
							  ObjectType = type,
							  HeapGeneration = heapGeneration,
							  HeapSize = heapSize
						  }).ToList();

			foreach(var objectData in objects)
			{
				this.outputWriter.WriteLine("0x{0:x12} {1:n0} {2}", objectData.ObjectId, objectData.HeapGeneration, objectData.ObjectType.Name);
			}

			this.outputWriter.WriteLineSeparator();
			this.outputWriter.WriteLine("Total Objects: {0:n0}", objects.Count);
			this.outputWriter.WriteLine("Total Heap Size Consumed: {0:n0}", objects.Sum(o => o.HeapSize));
		}