@@ -15,9 +15,11 @@ public class MemoryDiagnoser : IDiagnoser
1515 {
1616 private const string DiagnoserId = nameof ( MemoryDiagnoser ) ;
1717
18- public static readonly MemoryDiagnoser Default = new MemoryDiagnoser ( ) ;
18+ public static readonly MemoryDiagnoser Default = new MemoryDiagnoser ( new MemoryDiagnoserConfig ( displayGenColumns : true ) ) ;
1919
20- private MemoryDiagnoser ( ) { } // we want to have only a single instance of MemoryDiagnoser
20+ public MemoryDiagnoser ( MemoryDiagnoserConfig config ) => Config = config ;
21+
22+ public MemoryDiagnoserConfig Config { get ; }
2123
2224 public RunMode GetRunMode ( BenchmarkCase benchmarkCase ) => RunMode . NoOverhead ;
2325
@@ -33,9 +35,13 @@ public void Handle(HostSignal signal, DiagnoserActionParameters parameters) { }
3335
3436 public IEnumerable < Metric > ProcessResults ( DiagnoserResults diagnoserResults )
3537 {
36- yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen0 , diagnoserResults . GcStats . Gen0Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
37- yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen1 , diagnoserResults . GcStats . Gen1Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
38- yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen2 , diagnoserResults . GcStats . Gen2Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
38+ if ( diagnoserResults . GcStats . Gen0Collections > 0 && Config . DisplayGenColumns )
39+ yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen0 , diagnoserResults . GcStats . Gen0Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
40+ if ( diagnoserResults . GcStats . Gen1Collections > 0 && Config . DisplayGenColumns )
41+ yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen1 , diagnoserResults . GcStats . Gen1Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
42+ if ( diagnoserResults . GcStats . Gen2Collections > 0 && Config . DisplayGenColumns )
43+ yield return new Metric ( GarbageCollectionsMetricDescriptor . Gen2 , diagnoserResults . GcStats . Gen2Collections / ( double ) diagnoserResults . GcStats . TotalOperations * 1000 ) ;
44+
3945 yield return new Metric ( AllocatedMemoryMetricDescriptor . Instance , diagnoserResults . GcStats . GetBytesAllocatedPerOperation ( diagnoserResults . BenchmarkCase ) ) ;
4046 }
4147
@@ -50,6 +56,7 @@ private class AllocatedMemoryMetricDescriptor : IMetricDescriptor
5056 public UnitType UnitType => UnitType . Size ;
5157 public string Unit => SizeUnit . B . Name ;
5258 public bool TheGreaterTheBetter => false ;
59+ public int PriorityInCategory => GC . MaxGeneration + 1 ;
5360 }
5461
5562 private class GarbageCollectionsMetricDescriptor : IMetricDescriptor
@@ -63,6 +70,7 @@ private GarbageCollectionsMetricDescriptor(int generationId)
6370 Id = $ "Gen{ generationId } Collects";
6471 DisplayName = $ "Gen { generationId } ";
6572 Legend = $ "GC Generation { generationId } collects per 1000 operations";
73+ PriorityInCategory = generationId ;
6674 }
6775
6876 public string Id { get ; }
@@ -72,6 +80,7 @@ private GarbageCollectionsMetricDescriptor(int generationId)
7280 public UnitType UnitType => UnitType . Dimensionless ;
7381 public string Unit => "Count" ;
7482 public bool TheGreaterTheBetter => false ;
83+ public int PriorityInCategory { get ; }
7584 }
7685 }
7786}
0 commit comments