usingSystem;
usingSystem.Linq;
usingSystem.Collections.Generic;
usingMicrosoft.Diagnostics.Runtime;
namespaceCLRMD_Demo
{
classProgram
{
staticvoidMain(string[] args)
{
Console.WriteLine("ClrMD Demo");
// https://github.com/Microsoft/clrmd/blob/master/Documentation/GettingStarted.md// https://github.com/Microsoft/clrmd/blob/master/Documentation/ClrRuntime.mdvarpath=@"C:\Users\Owner\Downloads\__Matt__\HelloWorld.DMP";
using (DataTargetdataTarget=DataTarget.LoadCrashDump(path))
{
EnumerateVersions(dataTarget.ClrVersions);
ClrInforuntimeInfo=dataTarget.ClrVersions[0]; // just using the first runtimeClrRuntimeruntime=runtimeInfo.CreateRuntime();
// AppDomainsConsole.WriteLine("AppDomains:");
foreach (ClrAppDomaindomaininruntime.AppDomains)
{
Console.WriteLine(" ID: {0}", domain.Id);
Console.WriteLine(" Name: {0}", domain.Name);
Console.WriteLine(" Address: {0}", domain.Address);
}
Console.WriteLine("");
// Walking the stackforeach (ClrThreadthreadinruntime.Threads)
{
if (!thread.IsAlive)
continue;
Console.WriteLine("Thread {0:X}:", thread.OSThreadId);
foreach (ClrStackFrameframeinthread.StackTrace)
Console.WriteLine("{0,12:X} {1,12:X} {2}", frame.StackPointer, frame.InstructionPointer, frame.ToString());
Console.WriteLine();
}
// CLR Memory Regionsforeach (varregionin (fromrinruntime.EnumerateMemoryRegions()
wherer.Type!=ClrMemoryRegionType.ReservedGCSegmentgrouprbyr.Typeintoglettotal=g.Sum(p=> (uint)p.Size)
orderbytotaldescendingselectnew
{
TotalSize=total,
Count=g.Count(),
Type=g.Key
}))
{
Console.WriteLine("{0,6:n0} {1,12:n0} {2}", region.Count, region.TotalSize, region.Type.ToString());
}
}
}
privatestaticvoidEnumerateVersions(IList<ClrInfo> versions)
{
foreach (ClrInfoversioninversions)
{
Console.WriteLine("Found CLR Version: "+version.Version.ToString());
// This is the data needed to request the dac from the symbol server:ModuleInfodacInfo=version.DacInfo;
Console.WriteLine("Filesize: {0:X}", dacInfo.FileSize);
Console.WriteLine("Timestamp: {0:X}", dacInfo.TimeStamp);
Console.WriteLine("Dac File: {0}", dacInfo.FileName);
// If we just happen to have the correct dac file installed on the machine,// the "LocalMatchingDac" property will return its location on disk:stringdacLocation=version.LocalMatchingDac;
if (!string.IsNullOrEmpty(dacLocation))
Console.WriteLine("Local dac location: "+dacLocation);
// You may also download the dac from the symbol server, which is covered// in a later section of this tutorial.
}
}
}
}