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 basic benchmark project for Activity based SDK. #725

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions benchmarks/OpenTelemetrySdkBenchmarksActivity.cs
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);
}
}
}
54 changes: 54 additions & 0 deletions benchmarks/Tracing/ActivityCreationScenarios.cs
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;
}
}
}
5 changes: 5 additions & 0 deletions benchmarks/readme.md
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*