Skip to content
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Configs/ConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
Expand Down Expand Up @@ -111,7 +111,7 @@ public static class ConfigExtensions
[Obsolete("This method will soon be removed, please start using .AddLogicalGroupRules() instead.")]
[EditorBrowsable(EditorBrowsableState.Never)] public static IConfig With(this IConfig config, params BenchmarkLogicalGroupRule[] rules) => config.AddLogicalGroupRules(rules);
[PublicAPI] public static ManualConfig AddLogicalGroupRules(this IConfig config, params BenchmarkLogicalGroupRule[] rules) => config.With(c => c.AddLogicalGroupRules(rules));
[PublicAPI] public static ManualConfig AddBenchmarkEventHandler(this IConfig config, BenchmarkEventHandlerBase eventHandler) => config.With(c => c.AddBenchmarkEventHandler(eventHandler));
[PublicAPI] public static ManualConfig AddEventProcessor(this IConfig config, EventProcessorBase eventProcessor) => config.With(c => c.AddEventProcessor(eventProcessor));

[PublicAPI] public static ManualConfig HideColumns(this IConfig config, params string[] columnNames) => config.With(c => c.HideColumns(columnNames));
[PublicAPI] public static ManualConfig HideColumns(this IConfig config, params IColumn[] columns) => config.With(c => c.HideColumns(columns));
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Configs/DebugConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
Expand Down Expand Up @@ -62,7 +62,7 @@ public abstract class DebugConfig : IConfig
public IEnumerable<IDiagnoser> GetDiagnosers() => Array.Empty<IDiagnoser>();
public IEnumerable<IAnalyser> GetAnalysers() => Array.Empty<IAnalyser>();
public IEnumerable<HardwareCounter> GetHardwareCounters() => Array.Empty<HardwareCounter>();
public IEnumerable<BenchmarkEventHandlerBase> GetBenchmarkEventHandlers() => Array.Empty<BenchmarkEventHandlerBase>();
public IEnumerable<EventProcessorBase> GetEventProcessors() => Array.Empty<EventProcessorBase>();
public IEnumerable<IFilter> GetFilters() => Array.Empty<IFilter>();
public IEnumerable<IColumnHidingRule> GetColumnHidingRules() => Array.Empty<IColumnHidingRule>();

Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Configs/DefaultConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Filters;
Expand Down Expand Up @@ -109,7 +109,7 @@ public string ArtifactsPath

public IEnumerable<IFilter> GetFilters() => Array.Empty<IFilter>();

public IEnumerable<BenchmarkEventHandlerBase> GetBenchmarkEventHandlers() => Array.Empty<BenchmarkEventHandlerBase>();
public IEnumerable<EventProcessorBase> GetEventProcessors() => Array.Empty<EventProcessorBase>();

public IEnumerable<IColumnHidingRule> GetColumnHidingRules() => Array.Empty<IColumnHidingRule>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Configs/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
Expand All @@ -28,7 +28,7 @@ public interface IConfig
IEnumerable<HardwareCounter> GetHardwareCounters();
IEnumerable<IFilter> GetFilters();
IEnumerable<BenchmarkLogicalGroupRule> GetLogicalGroupRules();
IEnumerable<BenchmarkEventHandlerBase> GetBenchmarkEventHandlers();
IEnumerable<EventProcessorBase> GetEventProcessors();
IEnumerable<IColumnHidingRule> GetColumnHidingRules();

IOrderer? Orderer { get; }
Expand Down
10 changes: 5 additions & 5 deletions src/BenchmarkDotNet/Configs/ImmutableConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Filters;
using BenchmarkDotNet.Jobs;
Expand All @@ -32,7 +32,7 @@ public sealed class ImmutableConfig : IConfig
private readonly ImmutableHashSet<HardwareCounter> hardwareCounters;
private readonly ImmutableHashSet<IFilter> filters;
private readonly ImmutableArray<BenchmarkLogicalGroupRule> rules;
private readonly ImmutableHashSet<BenchmarkEventHandlerBase> eventHandlers;
private readonly ImmutableHashSet<EventProcessorBase> eventProcessors;
private readonly ImmutableArray<IColumnHidingRule> columnHidingRules;

internal ImmutableConfig(
Expand All @@ -47,7 +47,7 @@ internal ImmutableConfig(
ImmutableArray<BenchmarkLogicalGroupRule> uniqueRules,
ImmutableArray<IColumnHidingRule> uniqueColumnHidingRules,
ImmutableHashSet<Job> uniqueRunnableJobs,
ImmutableHashSet<BenchmarkEventHandlerBase> uniqueEventHandlers,
ImmutableHashSet<EventProcessorBase> uniqueEventProcessors,
ConfigUnionRule unionRule,
string artifactsPath,
CultureInfo cultureInfo,
Expand All @@ -69,7 +69,7 @@ internal ImmutableConfig(
rules = uniqueRules;
columnHidingRules = uniqueColumnHidingRules;
jobs = uniqueRunnableJobs;
eventHandlers = uniqueEventHandlers;
eventProcessors = uniqueEventProcessors;
UnionRule = unionRule;
ArtifactsPath = artifactsPath;
CultureInfo = cultureInfo;
Expand Down Expand Up @@ -100,7 +100,7 @@ internal ImmutableConfig(
public IEnumerable<HardwareCounter> GetHardwareCounters() => hardwareCounters;
public IEnumerable<IFilter> GetFilters() => filters;
public IEnumerable<BenchmarkLogicalGroupRule> GetLogicalGroupRules() => rules;
public IEnumerable<BenchmarkEventHandlerBase> GetBenchmarkEventHandlers() => eventHandlers;
public IEnumerable<EventProcessorBase> GetEventProcessors() => eventProcessors;
public IEnumerable<IColumnHidingRule> GetColumnHidingRules() => columnHidingRules;

public ILogger GetCompositeLogger() => new CompositeLogger(loggers);
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static ImmutableConfig Create(IConfig source)
var uniqueHidingRules = source.GetColumnHidingRules().ToImmutableArray();

var uniqueRunnableJobs = GetRunnableJobs(source.GetJobs()).ToImmutableHashSet();
var uniqueEventHandlers = source.GetBenchmarkEventHandlers().ToImmutableHashSet();
var uniqueEventProcessors = source.GetEventProcessors().ToImmutableHashSet();

return new ImmutableConfig(
uniqueColumnProviders,
Expand All @@ -67,7 +67,7 @@ public static ImmutableConfig Create(IConfig source)
uniqueRules,
uniqueHidingRules,
uniqueRunnableJobs,
uniqueEventHandlers,
uniqueEventProcessors,
source.UnionRule,
source.ArtifactsPath ?? DefaultConfig.Instance.ArtifactsPath,
source.CultureInfo,
Expand Down
10 changes: 5 additions & 5 deletions src/BenchmarkDotNet/Configs/ManualConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.EventHandlers;
using BenchmarkDotNet.EventProcessors;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Filters;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class ManualConfig : IConfig
private readonly HashSet<HardwareCounter> hardwareCounters = new HashSet<HardwareCounter>();
private readonly List<IFilter> filters = new List<IFilter>();
private readonly List<BenchmarkLogicalGroupRule> logicalGroupRules = new List<BenchmarkLogicalGroupRule>();
private readonly List<BenchmarkEventHandlerBase> eventHandlers = new List<BenchmarkEventHandlerBase>();
private readonly List<EventProcessorBase> eventProcessors = new List<EventProcessorBase>();
private readonly List<IColumnHidingRule> columnHidingRules = new List<IColumnHidingRule>();

public IEnumerable<IColumnProvider> GetColumnProviders() => columnProviders;
Expand All @@ -47,7 +47,7 @@ public class ManualConfig : IConfig
public IEnumerable<HardwareCounter> GetHardwareCounters() => hardwareCounters;
public IEnumerable<IFilter> GetFilters() => filters;
public IEnumerable<BenchmarkLogicalGroupRule> GetLogicalGroupRules() => logicalGroupRules;
public IEnumerable<BenchmarkEventHandlerBase> GetBenchmarkEventHandlers() => eventHandlers;
public IEnumerable<EventProcessorBase> GetEventProcessors() => eventProcessors;
public IEnumerable<IColumnHidingRule> GetColumnHidingRules() => columnHidingRules;

[PublicAPI] public ConfigOptions Options { get; set; }
Expand Down Expand Up @@ -224,9 +224,9 @@ public ManualConfig AddLogicalGroupRules(params BenchmarkLogicalGroupRule[] rule
return this;
}

public ManualConfig AddBenchmarkEventHandler(BenchmarkEventHandlerBase eventHandler)
public ManualConfig AddEventProcessor(EventProcessorBase eventProcessor)
{
this.eventHandlers.Add(eventHandler);
this.eventProcessors.Add(eventProcessor);
return this;
}

Expand Down

This file was deleted.

102 changes: 102 additions & 0 deletions src/BenchmarkDotNet/EventProcessors/CompositeEventProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.Results;
using BenchmarkDotNet.Validators;

namespace BenchmarkDotNet.EventProcessors
{
internal sealed class CompositeEventProcessor : EventProcessorBase
{
private readonly IReadOnlyCollection<EventProcessorBase> eventProcessors;

public CompositeEventProcessor(BenchmarkRunInfo[] benchmarkRunInfos)
{
var eventProcessors = new HashSet<EventProcessorBase>();

foreach (var info in benchmarkRunInfos)
eventProcessors.AddRange(info.Config.GetEventProcessors());

this.eventProcessors = eventProcessors;
}

public CompositeEventProcessor(IReadOnlyCollection<EventProcessorBase> eventProcessors)
{
this.eventProcessors = eventProcessors;
}

public override void OnStartValidationStage()
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnStartValidationStage();
}

public override void OnValidationError(ValidationError validationError)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnValidationError(validationError);
}

public override void OnEndValidationStage()
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnEndValidationStage();
}

public override void OnStartBuildStage(IReadOnlyList<BuildPartition> partitions)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnStartBuildStage(partitions);
}

public override void OnBuildComplete(BuildPartition buildPartition, BuildResult buildResult)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnBuildComplete(buildPartition, buildResult);
}

public override void OnEndBuildStage()
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnEndBuildStage();
}

public override void OnStartRunStage()
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnStartRunStage();
}

public override void OnEndRunStage()
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnEndRunStage();
}

public override void OnStartRunBenchmarksInType(Type type, IReadOnlyList<BenchmarkCase> benchmarks)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnStartRunBenchmarksInType(type, benchmarks);
}

public override void OnEndRunBenchmarksInType(Type type, Summary summary)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnEndRunBenchmarksInType(type, summary);
}

public override void OnEndRunBenchmark(BenchmarkCase benchmarkCase, BenchmarkReport report)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnEndRunBenchmark(benchmarkCase, report);
}

public override void OnStartRunBenchmark(BenchmarkCase benchmarkCase)
{
foreach (var eventProcessor in eventProcessors)
eventProcessor.OnStartRunBenchmark(benchmarkCase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
using BenchmarkDotNet.Toolchains.Results;
using BenchmarkDotNet.Validators;

namespace BenchmarkDotNet.EventHandlers
namespace BenchmarkDotNet.EventProcessors
{
public abstract class BenchmarkEventHandlerBase
public abstract class EventProcessorBase
{
public virtual void OnStartValidationStage() { }
public virtual void OnValidationError(ValidationError validationError) { }
public virtual void OnEndValidationStage() { }
public virtual void OnStartBuildStage() { }
public virtual void OnBuildFailed(BenchmarkCase benchmarkCase, BuildResult buildResult) { }
public virtual void OnStartBuildStage(IReadOnlyList<BuildPartition> partitions) { }
public virtual void OnBuildComplete(BuildPartition benchmarkCase, BuildResult buildResult) { }
public virtual void OnEndBuildStage() { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between OnBuildComplete and OnEndBuildStage? The first is for one partition and the latter is for all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the difference between them.

public virtual void OnStartRunStage() { }
public virtual void OnStartRunBenchmarksInType(Type type, IReadOnlyList<BenchmarkCase> benchmarks) { }
Expand Down
Loading