dotnet / BenchmarkDotNet

Powerful .NET library for benchmarking
https://benchmarkdotnet.org
MIT License
10.5k stars 966 forks source link

Feature Request: Add ability to automatically hide metric columns if value is not set #2629

Open filzrev opened 1 month ago

filzrev commented 1 month ago

When using ThreadingDiagnoser/ExceptionDiagnoser. Following metric columns are displayed always .

Is it able to automatically hide these columns if all metric values are 0 ?.

It seems to be able to change behaviors by modifying following code.

Excample benchmark code

 [ShortRunJob]
 [ThreadingDiagnoser]
 // [HideColumns(Column.CompletedWorkItems, Column.LockContentions, Column.Exceptions)]
 public class Benchmarks
 {
     [Benchmark]
     public void Benchmark()
     {
         Thread.Sleep(1);
     }
 }

Console Output

| Method    | Mean     | Error    | StdDev   | Exceptions | Completed Work Items | Lock Contentions |
|---------- |---------:|---------:|---------:|-----------:|---------------------:|-----------------:|
| Benchmark | 15.57 ms | 0.364 ms | 0.020 ms |          - |                    - |                - |
timcassell commented 1 month ago

It should be fairly easy to implement that behavior by changing the implementation of GetIsAvailable for those metric descriptors, similar to MemoryDiagnoser.

https://github.com/dotnet/BenchmarkDotNet/blob/ca5dfdf106affb0922f5b8002a67272a27d3fd03/src/BenchmarkDotNet/Diagnosers/MemoryDiagnoser.cs#L69

https://github.com/dotnet/BenchmarkDotNet/blob/ca5dfdf106affb0922f5b8002a67272a27d3fd03/src/BenchmarkDotNet/Diagnosers/ThreadingDiagnoser.cs#L65

https://github.com/dotnet/BenchmarkDotNet/blob/ca5dfdf106affb0922f5b8002a67272a27d3fd03/src/BenchmarkDotNet/Diagnosers/ThreadingDiagnoser.cs#L80

https://github.com/dotnet/BenchmarkDotNet/blob/ca5dfdf106affb0922f5b8002a67272a27d3fd03/src/BenchmarkDotNet/Diagnosers/ExceptionDiagnoser.cs#L52