Exemple #1
0
        /// <summary>
        /// Splits the heap report by GC generation.
        /// </summary>
        /// <returns>An array containing a heap report per GC generation. The index of the an array element denotes the GC generation.</returns>
        public HeapReport[] SplitByGeneration()
        {
            var maxGen = GC.MaxGeneration;

            //
            // Keep the hash sets and heap reports in separate arrays, so the core algorithm can do away
            // with traversing into the Objects property of the heap reports for each object.
            //

            var res  = new HeapReport[maxGen + 1];
            var gens = new ObjectSet[maxGen + 1];

            for (var i = 0; i <= maxGen; i++)
            {
                var set = new ObjectSet();
                gens[i] = set;
                res[i]  = new HeapReport(set);
            }

            //
            // Simply iterate over all objects and copy them to the set for the corresponding generation.
            //

            foreach (var obj in Objects)
            {
                gens[GC.GetGeneration(obj)].Add(obj);
            }

            return(res);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new heap usage analysis with a shared heap.
 /// </summary>
 /// <param name="reports">The reports for each heap partition.</param>
 /// <param name="shared">The report for the shared heap.</param>
 public HeapUsageAnalysis(Dictionary <HeapPartition, HeapReport> reports, HeapReport shared)
 {
     Reports = reports ?? throw new ArgumentNullException(nameof(reports));
     Shared  = shared ?? throw new ArgumentNullException(nameof(shared));
 }