Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event processor functionality #2420

Merged
merged 12 commits into from
Sep 21, 2023

Conversation

caaavik-msft
Copy link
Contributor

This addresses #2054 which is a feature request to have hooks which can enable other tools that are invoking BDN to display progress rather than having to parse live console output or to wait for all the benchmarks to complete to have the exporters run.

A full proposal and explanation of the events/hooks in this PR are covered in this comment: #2054 (comment)

There are potentially many more hooks that could be added like events for when a benchmark run enters a different stage, but they would likely need to be added as custom events sent through the Broker and supported by all the different executors/toolchains, which I didn't want to add at this stage. I'm open as well to modifying or adding extra events before merging this in to see what people think would be useful.

I've also included a EventHandlerBase class which is a base class that implements all the hooks as virtual methods, so that implementing classes only need to override the hooks they care about.

@cincuranet
Copy link
Contributor

Any reason why CompositeEventHandler does not derive from EventHandlerBase?

@caaavik-msft
Copy link
Contributor Author

Any reason why CompositeEventHandler does not derive from EventHandlerBase?

EventHandlerBase is just an implementation of the interface with virtual methods so that custom event handlers don't have to implement every hook and can just implement the hooks they care about. The CompositeEventHandler composes multiple event handlers into one, so by nature we want to ensure that every hook is implemented and handled, if we used the EventHandlerBase we may forget to update CompositeEventHandler if we add a new hook.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

Overall it looks good, but let's iterate on simplifying it a bit and unifying the naming.

Thank you for your contribution @caaavik-msft !

src/BenchmarkDotNet/Configs/ConfigExtensions.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/EventHandlers/EventHandlerBase.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/EventHandlers/IEventHandler.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/EventHandlers/IEventHandler.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/EventHandlers/IEventHandler.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs Outdated Show resolved Hide resolved
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

We are almost there, thank you for addressing the feedback @caaavik-msft !

@caaavik-msft caaavik-msft changed the title Add event handler functionality Add event processor functionality Sep 7, 2023
@caaavik-msft
Copy link
Contributor Author

@adamsitnik are we good to merge this in now?

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, but please rename the type before I hit the merge button.

Thank you @caaavik-msft !

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.

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs Outdated Show resolved Hide resolved
src/BenchmarkDotNet/EventProcessors/EventProcessorBase.cs Outdated Show resolved Hide resolved
@adamsitnik adamsitnik merged commit ad93765 into dotnet:master Sep 21, 2023
6 of 7 checks passed
@adamsitnik adamsitnik added this to the v0.13.9 milestone Sep 21, 2023
@@ -221,6 +224,12 @@ public ManualConfig AddLogicalGroupRules(params BenchmarkLogicalGroupRule[] rule
return this;
}

public ManualConfig AddEventProcessor(EventProcessor eventProcessor)
Copy link
Contributor

Choose a reason for hiding this comment

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

@adamsitnik, @caaavik-msft

nit: it's unlikely that the users will need more than one instance

While this may be true, this makes it the only one of the Add... methods that doesn't accept a params array. Personally, I would prefer the API consistency.

@mawosoft
Copy link
Contributor

Also, ManualConfig.Add(IConfig config) and, by extension, ManualConfig.Union(IConfig globalConfig, IConfig localConfig) and ManualConfig.Create(IConfig config) don't copy the event processor(s) from the source.

@timcassell
Copy link
Collaborator

@caaavik-msft Can you address @mawosoft's comment in another PR (merging configs)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom logging/visualization during the benchmark run
6 participants