示例#1
0
        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 ProcessAllocations GetProcessAllocations(int pid)
 {
     if (!_processes.Allocations.TryGetValue(pid, out var allocations))
     {
         allocations = new ProcessAllocations(pid);
         _processes.Allocations[pid] = allocations;
     }
     return(allocations);
 }