Let us see the output first and then check the Plug code required to get the same.
Now let us check the Analysis code snippet!
void GraphTop10HeapByReservedSize()
{
//Top 10 Heaps by Reserved Memory Size
IEnumerable<NTHeap> _Top10HeapByReservedSize =
Analyzer.HeapCollection.AsQueryable().OrderByDescending(h => h.ReservedMemory).Take(10);
double largestSize = 0;
WriteBoldLine("Top 10 Heaps by Reserved Size");
foreach (NTHeap h in _Top10HeapByReservedSize)
{
if (largestSize == 0)
{
largestSize = h.ReservedMemory;
WriteGraphLine(GraphColors.LightGreen, 100, //1st element is always 100%
string.Format("Heap Handle - {0}, Size - {1}, Name - {2}",
CreateAnchor(AnchorType.Heap, Analyzer.GetAsHexString(h.Handle)),
Analyzer.FormatByteToString(h.ReservedMemory),
h.HeapName
));
}
else
//Calculate percentage relative to the 1st element
WriteGraphLine(GraphColors.LightGreen, (int)((h.ReservedMemory/largestSize)*100) ,
string.Format("Heap Handle - {0}, Size - {1}, Name - {2}",
CreateAnchor(AnchorType.Heap, Analyzer.GetAsHexString(h.Handle)),
Analyzer.FormatByteToString(h.ReservedMemory),
h.HeapName
));
}
WriteBlankLine();
WriteBlankLine();
}
You must’ve noticed a function called ‘CreateAnchor’ which is actually used to link that Heap handle to details of Heap in the report… You can see how easy it is to use Lambda expression to get the results we need. Drawing graph has been never this easy. Isn’t it?
Now here is a question. How to show graph for Top 10 Heaps by Committed Size? No prizes for answer!