private ProcessAllocationInfo GetProcessAllocations(int pid) { if (!_processes.Allocations.TryGetValue(pid, out var allocations)) { allocations = new ProcessAllocationInfo(pid); _processes.Allocations[pid] = allocations; } return(allocations); }
private static void ShowResults(string name, ProcessAllocationInfo 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.GetAllocations().OrderByDescending(a => a.Size) : allocations.GetAllocations().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(); Console.WriteLine(); }