-
Notifications
You must be signed in to change notification settings - Fork 773
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 benchmark for SuppressInstrumentation #1049
Closed
alanwest
wants to merge
3
commits into
open-telemetry:master
from
alanwest:alanwest/suppress-benchmarks
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// <copyright file="DummyActivityProcessor.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using OpenTelemetry.Trace; | ||
|
||
internal class DummyActivityProcessor : ActivityProcessor | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
docs/trace/benchmark/SuppressInstrumentationBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// <copyright file="SuppressInstrumentationBenchmarks.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System.Diagnostics; | ||
using BenchmarkDotNet.Attributes; | ||
using OpenTelemetry; | ||
|
||
[MemoryDiagnoser] | ||
public class SuppressInstrumentationBenchmarks | ||
{ | ||
private readonly ActivitySource sourceWithSuppressInstrumentation = new ActivitySource("Benchmark.SuppressInstrumentation"); | ||
private readonly ActivitySource sourceWithNoneListener = new ActivitySource("Benchmark.NoneListener"); | ||
private readonly ActivitySource sourceWithAllDataAndRecordedListner = new ActivitySource("Benchmark.AllDataAndRecordedListner"); | ||
|
||
public SuppressInstrumentationBenchmarks() | ||
{ | ||
Activity.DefaultIdFormat = ActivityIdFormat.W3C; | ||
|
||
ActivitySource.AddActivityListener(new ActivityListener | ||
{ | ||
ActivityStarted = null, | ||
ActivityStopped = null, | ||
ShouldListenTo = (activitySource) => activitySource.Name == this.sourceWithSuppressInstrumentation.Name, | ||
GetRequestedDataUsingParentId = (ref ActivityCreationOptions<string> options) => { return Sdk.SuppressInstrumentation ? ActivityDataRequest.None : ActivityDataRequest.AllDataAndRecorded; }, | ||
GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => { return Sdk.SuppressInstrumentation ? ActivityDataRequest.None : ActivityDataRequest.AllDataAndRecorded; }, | ||
}); | ||
|
||
ActivitySource.AddActivityListener(new ActivityListener | ||
{ | ||
ActivityStarted = null, | ||
ActivityStopped = null, | ||
ShouldListenTo = (activitySource) => activitySource.Name == this.sourceWithNoneListener.Name, | ||
GetRequestedDataUsingParentId = (ref ActivityCreationOptions<string> options) => ActivityDataRequest.None, | ||
GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => ActivityDataRequest.None, | ||
}); | ||
|
||
ActivitySource.AddActivityListener(new ActivityListener | ||
{ | ||
ActivityStarted = null, | ||
ActivityStopped = null, | ||
ShouldListenTo = (activitySource) => activitySource.Name == this.sourceWithAllDataAndRecordedListner.Name, | ||
GetRequestedDataUsingParentId = (ref ActivityCreationOptions<string> options) => ActivityDataRequest.AllDataAndRecorded, | ||
GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => ActivityDataRequest.AllDataAndRecorded, | ||
}); | ||
} | ||
|
||
[Benchmark] | ||
public void SuppressInstrumentationFalse() | ||
{ | ||
using (var activity = this.sourceWithSuppressInstrumentation.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void SuppressInstrumentationTrue() | ||
{ | ||
using (SuppressInstrumentationScope.Begin()) | ||
{ | ||
using (var activity = this.sourceWithSuppressInstrumentation.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void SuppressInstrumentationTrueNested() | ||
{ | ||
using (SuppressInstrumentationScope.Begin()) | ||
{ | ||
using (SuppressInstrumentationScope.Begin()) | ||
{ | ||
using (var activity = this.sourceWithSuppressInstrumentation.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void NoneListener() | ||
{ | ||
using (var activity = this.sourceWithNoneListener.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void AllDataAndRecordedListener1() | ||
{ | ||
using (var activity = this.sourceWithAllDataAndRecordedListner.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void AllDataAndRecordedListener2() | ||
{ | ||
var b = Sdk.SuppressInstrumentation; | ||
using (var activity = this.sourceWithAllDataAndRecordedListner.StartActivity("Benchmark")) | ||
{ | ||
// this activity will be created and feed into an ActivityListener that simply drops everything on the floor | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this so you can run like:
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alanwest FYI the benchmark project in /test/ is already set up for that. We should combine these two benchmark projects at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep noticed that, that's where I copied the pattern. Put these next to @reyang's other benchmarks for now since they are similar, but we can discuss a better place once we're through with analysis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping back from #1039 (comment).