Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/BenchmarkDotNet/Attributes/ExceptionDiagnoserAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class ExceptionDiagnoserAttribute : Attribute, IConfigSource
{
public IConfig Config { get; }

public ExceptionDiagnoserAttribute() => Config = ManualConfig.CreateEmpty().AddDiagnoser(ExceptionDiagnoser.Default);
/// <param name="displayExceptions">Display Exceptions column. True by default.</param>
public ExceptionDiagnoserAttribute(bool displayExceptions = true)
{
Config = ManualConfig.CreateEmpty().AddDiagnoser(new ExceptionDiagnoser(new ExceptionDiagnoserConfig(displayExceptions)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class ThreadingDiagnoserAttribute : Attribute, IConfigSource
{
public IConfig Config { get; }

public ThreadingDiagnoserAttribute() => Config = ManualConfig.CreateEmpty().AddDiagnoser(ThreadingDiagnoser.Default);
/// <param name="displayWorkItemsColumn">Display Work Items column. True by default.</param>
/// <param name="displayLockContentionsColumn">Display Lock Contentions column. True by default.</param>
public ThreadingDiagnoserAttribute(bool displayWorkItemsColumn = true, bool displayLockContentionsColumn = true)
{
Config = ManualConfig.CreateEmpty().AddDiagnoser(new ThreadingDiagnoser(new ThreadingDiagnoserConfig(displayWorkItemsColumn, displayLockContentionsColumn)));
}
}
}
11 changes: 9 additions & 2 deletions src/BenchmarkDotNet/Diagnosers/ExceptionDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace BenchmarkDotNet.Diagnosers
{
public class ExceptionDiagnoser : IDiagnoser
{
public static readonly ExceptionDiagnoser Default = new ExceptionDiagnoser();
public static readonly ExceptionDiagnoser Default = new ExceptionDiagnoser(new ExceptionDiagnoserConfig(true));

public ExceptionDiagnoser(ExceptionDiagnoserConfig config) => Config = config;

public ExceptionDiagnoserConfig Config { get; }

private ExceptionDiagnoser() { }

Expand All @@ -32,7 +36,10 @@ public void Handle(HostSignal signal, DiagnoserActionParameters parameters) { }

public IEnumerable<Metric> ProcessResults(DiagnoserResults results)
{
yield return new Metric(ExceptionsFrequencyMetricDescriptor.Instance, results.ExceptionFrequency);
if (!Config.DisplayExceptionsIfZeroValue && results.ExceptionFrequency == 0)
{
yield return new Metric(ExceptionsFrequencyMetricDescriptor.Instance, results.ExceptionFrequency);
}
}

public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters) => Enumerable.Empty<ValidationError>();
Expand Down
15 changes: 15 additions & 0 deletions src/BenchmarkDotNet/Diagnosers/ExceptionDiagnoserConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using JetBrains.Annotations;

namespace BenchmarkDotNet.Diagnosers;

public class ExceptionDiagnoserConfig
{
/// <param name="displayExceptionsIfZeroValue">Display Exceptions column if it's value is not calculated. True by default.</param>
[PublicAPI]
public ExceptionDiagnoserConfig(bool displayExceptionsIfZeroValue = true)
{
DisplayExceptionsIfZeroValue = displayExceptionsIfZeroValue;
}

public bool DisplayExceptionsIfZeroValue { get; }
}
17 changes: 14 additions & 3 deletions src/BenchmarkDotNet/Diagnosers/ThreadingDiagnoser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ namespace BenchmarkDotNet.Diagnosers
{
public class ThreadingDiagnoser : IDiagnoser
{
public static readonly ThreadingDiagnoser Default = new ThreadingDiagnoser();
public static readonly ThreadingDiagnoser Default = new ThreadingDiagnoser(new ThreadingDiagnoserConfig(true, true));

public ThreadingDiagnoser(ThreadingDiagnoserConfig config) => Config = config;

public ThreadingDiagnoserConfig Config { get; }

private ThreadingDiagnoser() { }

Expand All @@ -33,8 +37,15 @@ public void Handle(HostSignal signal, DiagnoserActionParameters parameters) { }

public IEnumerable<Metric> ProcessResults(DiagnoserResults results)
{
yield return new Metric(CompletedWorkItemCountMetricDescriptor.Instance, results.ThreadingStats.CompletedWorkItemCount / (double)results.ThreadingStats.TotalOperations);
yield return new Metric(LockContentionCountMetricDescriptor.Instance, results.ThreadingStats.LockContentionCount / (double)results.ThreadingStats.TotalOperations);
if (!Config.DisplayWorkItemsColumnIfZeroValue && results.ThreadingStats.CompletedWorkItemCount == 0)
{
yield return new Metric(CompletedWorkItemCountMetricDescriptor.Instance, results.ThreadingStats.CompletedWorkItemCount / (double)results.ThreadingStats.TotalOperations);
}

if (!Config.DisplayLockContentionsColumnIfZeroValue && results.ThreadingStats.LockContentionCount == 0)
{
yield return new Metric(LockContentionCountMetricDescriptor.Instance, results.ThreadingStats.LockContentionCount / (double)results.ThreadingStats.TotalOperations);
}
}

public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters)
Expand Down
18 changes: 18 additions & 0 deletions src/BenchmarkDotNet/Diagnosers/ThreadingDiagnoserConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using JetBrains.Annotations;

namespace BenchmarkDotNet.Diagnosers;

public class ThreadingDiagnoserConfig
{
/// <param name="displayWorkItemsColumnIfZeroValue">Display Work Items column if it's value is not calculated. True by default.</param>
/// <param name="displayLockContentionsColumnIfZeroValue">Display Lock Contentions column if it's value is not calculated. True by default.</param>
[PublicAPI]
public ThreadingDiagnoserConfig(bool displayWorkItemsColumnIfZeroValue = true, bool displayLockContentionsColumnIfZeroValue = true)
{
DisplayWorkItemsColumnIfZeroValue = displayWorkItemsColumnIfZeroValue;
DisplayLockContentionsColumnIfZeroValue = displayLockContentionsColumnIfZeroValue;
}
public bool DisplayWorkItemsColumnIfZeroValue { get; }

public bool DisplayLockContentionsColumnIfZeroValue { get; }
}