private static void ShowResults(string name, MethodStore methods, ProcessAllocations allocations, bool sortBySize, int topTypesLimit) { Console.WriteLine($"Memory allocations for {name}"); Console.WriteLine(); Console.WriteLine("---------------------------------------------------------"); Console.WriteLine(" Count Size Type"); Console.WriteLine("---------------------------------------------------------"); IEnumerable <AllocationInfo> types = (sortBySize) ? allocations.GetAllAllocations().OrderByDescending(a => a.Size) : allocations.GetAllAllocations().OrderByDescending(a => a.Count) ; if (topTypesLimit != -1) { types = types.Take(topTypesLimit); } foreach (var allocation in types) { Console.WriteLine($"{allocation.Count,9} {allocation.Size,11} {allocation.TypeName}"); Console.WriteLine(); DumpStacks(allocation, methods); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(); }
private static void DumpStack(AddressStack stack, MethodStore methods) { var callstack = stack.Stack; for (int i = 0; i < Math.Min(10, callstack.Count); i++) { Console.WriteLine($" {methods.GetFullName(callstack[i])}"); } }
private MethodStore GetProcessMethods(int pid) { if (!_processes.Methods.TryGetValue(pid, out var methods)) { methods = new MethodStore(pid); _processes.Methods[pid] = methods; } return(methods); }
private static void DumpStacks(AllocationInfo allocation, MethodStore methods) { var stacks = allocation.Stacks.OrderByDescending(s => s.Count).Take(10); foreach (var stack in stacks) { Console.WriteLine($"{stack.Count,6} allocations"); Console.WriteLine("----------------------------------"); DumpStack(stack.Stack, methods); Console.WriteLine(); } }