Eventsource perf (#1383)

* Added perf test for ActivityStarted event.

* Moved ActivityStarted & ActivityStopped events behind an IsEnabled check.

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
Mikel Blanchard 2020-10-22 15:51:01 -07:00 committed by GitHub
parent a5e7d6e631
commit 478569966f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 5 deletions

View File

@ -17,9 +17,9 @@
using System;
#if DEBUG
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#endif
using System.Diagnostics;
using System.Diagnostics.Tracing;
namespace OpenTelemetry.Internal
@ -89,6 +89,24 @@ namespace OpenTelemetry.Internal
}
}
[NonEvent]
public void ActivityStarted(Activity activity)
{
if (this.IsEnabled(EventLevel.Verbose, (EventKeywords)(-1)))
{
this.ActivityStarted(activity.OperationName, activity.Id);
}
}
[NonEvent]
public void ActivityStopped(Activity activity)
{
if (this.IsEnabled(EventLevel.Verbose, (EventKeywords)(-1)))
{
this.ActivityStopped(activity.OperationName, activity.Id);
}
}
[Event(1, Message = "Span processor queue size reached maximum. Throttling spans.", Level = EventLevel.Warning)]
public void SpanProcessorQueueIsExhausted()
{

View File

@ -77,7 +77,7 @@ namespace OpenTelemetry.Trace
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "ActivityProcessor is hot path")]
public void Start(Activity activity, ActivityKind kind)
{
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id);
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);
SetKindProperty(activity, kind);
this.getRequestedDataAction(activity);
@ -94,7 +94,7 @@ namespace OpenTelemetry.Trace
/// <param name="activity"><see cref="Activity"/> to be stopped.</param>
public void Stop(Activity activity)
{
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity.OperationName, activity.Id);
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity);
if (activity?.IsAllDataRequested ?? false)
{

View File

@ -69,7 +69,7 @@ namespace OpenTelemetry.Trace
// Callback when Activity is started.
ActivityStarted = (activity) =>
{
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id);
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);
if (!activity.IsAllDataRequested)
{
@ -86,7 +86,7 @@ namespace OpenTelemetry.Trace
// Callback when Activity is stopped.
ActivityStopped = (activity) =>
{
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity.OperationName, activity.Id);
OpenTelemetrySdkEventSource.Log.ActivityStopped(activity);
if (!activity.IsAllDataRequested)
{

View File

@ -0,0 +1,48 @@
// <copyright file="EventSourceBenchmarks.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.Internal;
namespace OpenTelemetry.Benchmarks
{
[MemoryDiagnoser]
public class EventSourceBenchmarks
{
[Benchmark]
public void EventWithIdAllocation()
{
Activity activity = new Activity("TestActivity");
activity.SetIdFormat(ActivityIdFormat.W3C);
activity.Start();
activity.Stop();
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id);
}
[Benchmark]
public void EventWithCheck()
{
Activity activity = new Activity("TestActivity");
activity.SetIdFormat(ActivityIdFormat.W3C);
activity.Start();
activity.Stop();
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);
}
}
}