-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic benchmark project for Activity based SDK. (#725)
* Add basic benchmark project for Activity based SDK. * readme separate
- Loading branch information
1 parent
2fe5100
commit fa69fb0
Showing
4 changed files
with
118 additions
and
0 deletions.
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
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,56 @@ | ||
// <copyright file="OpenTelemetrySdkBenchmarksActivity.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 Benchmarks.Tracing; | ||
using OpenTelemetry.Trace.Configuration; | ||
|
||
namespace Benchmarks | ||
{ | ||
[MemoryDiagnoser] | ||
public class OpenTelemetrySdkBenchmarksActivity | ||
{ | ||
private readonly ActivitySource BenchMarkSource = new ActivitySource("BenchMark"); | ||
|
||
public OpenTelemetrySdkBenchmarksActivity() | ||
{ | ||
// Not configuring pipeline, which will result in default NoOpActivityProcessor. | ||
var openTel = OpenTelemetrySdk.EnableOpenTelemetry( | ||
(builder) => builder.AddActivitySource("BenchMark") | ||
); | ||
} | ||
|
||
[Benchmark] | ||
public Activity CreateActivity_NoOpProcessor() | ||
{ | ||
return ActivityCreationScenarios.CreateActivity(this.BenchMarkSource); | ||
} | ||
|
||
|
||
[Benchmark] | ||
public Activity CreateActivity_WithAttributes_NoOpProcessor() | ||
{ | ||
return ActivityCreationScenarios.CreateActivityWithAttributes(this.BenchMarkSource); | ||
} | ||
|
||
[Benchmark] | ||
public Activity CreateActivity_WithAttributesAndCustomProp_NoOpProcessor() | ||
{ | ||
return ActivityCreationScenarios.CreateActivityWithAttributesAndCustomProperty(this.BenchMarkSource); | ||
} | ||
} | ||
} |
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,54 @@ | ||
// <copyright file="ActivityCreationScenarios.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 OpenTelemetry.Trace; | ||
|
||
namespace Benchmarks.Tracing | ||
{ | ||
internal class ActivityCreationScenarios | ||
{ | ||
public static Activity CreateActivity(ActivitySource source) | ||
{ | ||
var activity = source.StartActivity("name"); | ||
activity?.Stop(); | ||
return activity; | ||
} | ||
|
||
public static Activity CreateActivityWithAttributes(ActivitySource source) | ||
{ | ||
var activity = source.StartActivity("name"); | ||
activity?.AddTag("tag1", "value1"); | ||
activity?.AddTag("tag2", "value2"); | ||
activity?.AddTag("customPropTag1", "somecustomValue"); | ||
activity?.Stop(); | ||
return activity; | ||
} | ||
|
||
public static Activity CreateActivityWithAttributesAndCustomProperty(ActivitySource source) | ||
{ | ||
var activity = source.StartActivity("name"); | ||
activity?.AddTag("tag1", "value1"); | ||
activity?.AddTag("tag2", "value2"); | ||
|
||
// use custom property instead of tags | ||
// activity?.AddTag("customPropTag1", "somecustomValue"); | ||
activity?.SetCustomProperty("customPropTag1", "somecustomValue"); | ||
activity?.Stop(); | ||
return activity; | ||
} | ||
} | ||
} |
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,5 @@ | ||
Use the following example to run Benchmarks from command line: | ||
(change parameters as necessary) | ||
|
||
1. navigate to opentelemetry-dotnet\src\benchmarks directory and run the following | ||
2. dotnet run --framework netcoreapp3.1 --configuration Release --filter *OpenTelemetrySdkBenchmarksActivity* |