Use LINQPad as a Memory Profiler with 'ClrMD.Extensions'!
Hi,
I'd like to share a project I recently did with the LINQPad community. 'ClrMD' is an awesome library built by Microsoft, it allows you to query objects in a crash dump or live process with an object oriented API. 'ClrMD.Extensions' adds some functionality and allows you to easily use ClrMD with LINQPad.
The project is available on GitHub: https://github.com/JeffCyr/ClrMD.Extensions
This is the kind of query you can do with this library:
// This query will list the 100 types with most instances in the dump.
ClrMDSession session = ClrMDSession.LoadCrashDump(@C:\Dumps\YourDumpFile.dmp);
var stats = from o in session.AllObjects // Start with all objects
// Group by object type.
group o by o.Type into typeGroup
// Get the instance count of this type.
let count = typeGroup.Count()
// Get the memory usage of all instances of this type
let totalSize = typeGroup.Sum(item => (int)item.Size)
// Orderby to get objects with most instance count first
orderby count descending
select new
{
Type = typeGroup.Key.Name,
Count = count,
TotalSize = ((double)totalSize / 1024 / 1024).ToString("0.## MB"),
// Get the first 100 instances of the type.
First100Objects = typeGroup.Take(100),
}
stats.Take(100).Dump(depth:1);
I'd like to share a project I recently did with the LINQPad community. 'ClrMD' is an awesome library built by Microsoft, it allows you to query objects in a crash dump or live process with an object oriented API. 'ClrMD.Extensions' adds some functionality and allows you to easily use ClrMD with LINQPad.
The project is available on GitHub: https://github.com/JeffCyr/ClrMD.Extensions
This is the kind of query you can do with this library:
// This query will list the 100 types with most instances in the dump.
ClrMDSession session = ClrMDSession.LoadCrashDump(@C:\Dumps\YourDumpFile.dmp);
var stats = from o in session.AllObjects // Start with all objects
// Group by object type.
group o by o.Type into typeGroup
// Get the instance count of this type.
let count = typeGroup.Count()
// Get the memory usage of all instances of this type
let totalSize = typeGroup.Sum(item => (int)item.Size)
// Orderby to get objects with most instance count first
orderby count descending
select new
{
Type = typeGroup.Key.Name,
Count = count,
TotalSize = ((double)totalSize / 1024 / 1024).ToString("0.## MB"),
// Get the first 100 instances of the type.
First100Objects = typeGroup.Take(100),
}
stats.Take(100).Dump(depth:1);