Add basic benchmark project for Activity based SDK. (#725)
* Add basic benchmark project for Activity based SDK. * readme separate
This commit is contained in:
parent
2fe5100594
commit
fa69fb0a2b
|
|
@ -81,6 +81,9 @@ EndProject
|
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Shims.OpenTracing.Tests", "test\OpenTelemetry.Shims.OpenTracing.Tests\OpenTelemetry.Shims.OpenTracing.Tests.csproj", "{49A7853F-5B6F-4B65-A781-7D29A1C92164}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{0169B149-FB8B-46F4-9EF7-8A0E69F8FAAF}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
benchmarks\readme.md = benchmarks\readme.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "benchmarks\Benchmarks.csproj", "{CEB7F146-81DC-41DB-8015-140EC6A64E6C}"
|
||||
EndProject
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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*
|
||||
Loading…
Reference in New Issue