There are times when these automated tools don’t cover everything what we need out of memory dumps. Sometimes information in the dumps might not be required for reports but only required to be checked in specific scenarios. Interactive debugging option in Debug Analyzer.NET is just for that but powered with the same simplicity and object model.
In the previous post I discussed how simple it is to draw graph in such a small number of lines. Let us see how the same information can be added as a PlugCommand for Interactive Debugging session.
//Function Attributes required to enable the function as PlugCommand
[PlugCommand(
Command="top10heapbyreservedsize",
Description="Shows Top 10 Heap By Reserved Size",
Usage="Top10HeapByReservedSize")]
public string Top10HeapByReservedSize()
{
//Top 10 heaps by reserved memory
IEnumerable<NTHeap> _Top10HeapByReservedSize =
Analyzer.HeapCollection.AsQueryable().OrderByDescending(h => h.ReservedMemory).Take(10);
StringBuilder heapstr = new StringBuilder();
heapstr.AppendFormat("{0} {1} {2} {3}",
"[Handle]".PadRight(10),
"[Reserve Size]".PadLeft(15),
"[Heap Name]",
Environment.NewLine);
foreach (NTHeap h in _Top10HeapByReservedSize)
{
heapstr.AppendFormat("{0} {1} {2} {3}",
Analyzer.GetAsHexString(h.Handle),
Analyzer.FormatByteToString(h.ReservedMemory).PadLeft(15),
h.HeapName,
Environment.NewLine);
}
return heapstr.ToString();
}
So the only requirement for PlugCommand is that it should be a function which returns a string and all string parameters (if any) and the “PlugCommand” attribute should be added which publishes the function as a Command to the ‘Plug Framework’
Lets see how it looks like in the output of Interactive session below
Please let me know the feedback through comments!