|
| 1 | +using BenchmarkDotNet.Analysers; |
| 2 | +using BenchmarkDotNet.Columns; |
| 3 | +using BenchmarkDotNet.Engines; |
| 4 | +using BenchmarkDotNet.Exporters; |
| 5 | +using BenchmarkDotNet.Loggers; |
| 6 | +using BenchmarkDotNet.Reports; |
| 7 | +using BenchmarkDotNet.Running; |
| 8 | +using BenchmarkDotNet.Validators; |
| 9 | +using System; |
| 10 | +using System.Collections.Generic; |
| 11 | +using System.Linq; |
| 12 | + |
| 13 | +namespace BenchmarkDotNet.Diagnosers |
| 14 | +{ |
| 15 | + public class ExceptionDiagnoser : IDiagnoser |
| 16 | + { |
| 17 | + public static readonly ExceptionDiagnoser Default = new ExceptionDiagnoser(); |
| 18 | + |
| 19 | + private ExceptionDiagnoser() { } |
| 20 | + |
| 21 | + public IEnumerable<string> Ids => new[] { nameof(ExceptionDiagnoser) }; |
| 22 | + |
| 23 | + public IEnumerable<IExporter> Exporters => Array.Empty<IExporter>(); |
| 24 | + |
| 25 | + public IEnumerable<IAnalyser> Analysers => Array.Empty<IAnalyser>(); |
| 26 | + |
| 27 | + public void DisplayResults(ILogger logger) { } |
| 28 | + |
| 29 | + public RunMode GetRunMode(BenchmarkCase benchmarkCase) => RunMode.NoOverhead; |
| 30 | + |
| 31 | + public void Handle(HostSignal signal, DiagnoserActionParameters parameters) { } |
| 32 | + |
| 33 | + public IEnumerable<Metric> ProcessResults(DiagnoserResults results) |
| 34 | + { |
| 35 | + yield return new Metric(ExceptionsFrequencyMetricDescriptor.Instance, results.ExceptionFrequency); |
| 36 | + } |
| 37 | + |
| 38 | + public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters) => Enumerable.Empty<ValidationError>(); |
| 39 | + |
| 40 | + private class ExceptionsFrequencyMetricDescriptor : IMetricDescriptor |
| 41 | + { |
| 42 | + internal static readonly IMetricDescriptor Instance = new ExceptionsFrequencyMetricDescriptor(); |
| 43 | + |
| 44 | + public string Id => "ExceptionFrequency"; |
| 45 | + public string DisplayName => Column.Exceptions; |
| 46 | + public string Legend => "Exceptions thrown per single operation"; |
| 47 | + public string NumberFormat => "#0.0000"; |
| 48 | + public UnitType UnitType => UnitType.Dimensionless; |
| 49 | + public string Unit => "Count"; |
| 50 | + public bool TheGreaterTheBetter => false; |
| 51 | + public int PriorityInCategory => 0; |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments