Exemple #1
0
        private static void WriteFormattedHeapStats(TextWriter tw, string prefix, GCHeapStats heapStats)
        {
            var data = new List <Tuple <string, string> >();

            data.Add(FormatWithValue(heapStats, h => h.Depth));
            data.Add(FormatWithValue(heapStats, h => h.FinalizationPromotedCount));
            data.Add(FormatWithValue(heapStats, h => h.FinalizationPromotedSize));
            data.Add(FormatWithValue(heapStats, h => h.GCHandleCount));
            data.Add(FormatWithValue(heapStats, h => h.GenerationSize0));
            data.Add(FormatWithValue(heapStats, h => h.GenerationSize1));
            data.Add(FormatWithValue(heapStats, h => h.GenerationSize2));
            data.Add(FormatWithValue(heapStats, h => h.GenerationSize3));
            data.Add(FormatWithValue(heapStats, h => h.PinnedObjectCount));
            data.Add(FormatWithValue(heapStats, h => h.SinkBlockCount));
            data.Add(FormatWithValue(heapStats, h => h.TotalHeapSize));
            data.Add(FormatWithValue(heapStats, h => h.TotalPromoted));
            data.Add(FormatWithValue(heapStats, h => h.TotalPromotedSize0));
            data.Add(FormatWithValue(heapStats, h => h.TotalPromotedSize1));
            data.Add(FormatWithValue(heapStats, h => h.TotalPromotedSize2));
            data.Add(FormatWithValue(heapStats, h => h.TotalPromotedSize3));

            int maxName  = data.Max(d => d.Item1.Length);
            int maxValue = data.Max(d => d.Item2.Length);

            foreach (var entry in data)
            {
                tw.WriteLine("{0}    {1}   {2}", prefix, entry.Item1.PadRight(maxName), entry.Item2.PadLeft(maxValue));
            }
        }
Exemple #2
0
        private static Tuple <string, string> FormatWithValue <T>(GCHeapStats s, Expression <Func <GCHeapStats, T> > exp)
        {
            if (!(exp.Body is MemberExpression body))
            {
                var ubody = (UnaryExpression)exp.Body;
                body = ubody.Operand as MemberExpression;
            }

            string name = body.Member.Name;

            name = Regex.Replace(name, @"(\B[A-Z0-9])", " $1").ToLowerInvariant().Replace("g c ", "GC ");

            return(Tuple.Create(name, $"{exp.Compile().Invoke(s):N0}"));
        }