Skip to content

Commit

Permalink
tracing: udpate benchmarks to include event listeners
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
adityamaru committed Apr 25, 2022
1 parent bd66e9a commit a40901a
Showing 1 changed file with 50 additions and 21 deletions.
71 changes: 50 additions & 21 deletions pkg/util/tracing/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ func BenchmarkTracer_StartSpanCtx(b *testing.B) {
staticLogTags.Add("foo", "bar")

for _, tc := range []struct {
name string
defaultMode TracingMode
parent bool
opts []SpanOption
name string
defaultMode TracingMode
parent bool
withEventListener bool
opts []SpanOption
}{
{"none", TracingModeOnDemand, false, nil},
{"real", TracingModeActiveSpansRegistry, false, nil},
{"real,logtag", TracingModeActiveSpansRegistry, false, []SpanOption{WithLogTags(&staticLogTags)}},
{"real,autoparent", TracingModeActiveSpansRegistry, true, nil},
{"real,manualparent", TracingModeActiveSpansRegistry, true, []SpanOption{WithDetachedRecording()}},
{name: "none", defaultMode: TracingModeOnDemand},
{name: "real", defaultMode: TracingModeActiveSpansRegistry},
{name: "real,logtag", defaultMode: TracingModeActiveSpansRegistry,
opts: []SpanOption{WithLogTags(&staticLogTags)}},
{name: "real,autoparent", defaultMode: TracingModeActiveSpansRegistry, parent: true},
{name: "real,manualparent", defaultMode: TracingModeActiveSpansRegistry, parent: true,
opts: []SpanOption{WithDetachedRecording()}},
{name: "real,autoparent,withEventListener", defaultMode: TracingModeActiveSpansRegistry,
parent: true, withEventListener: true},
{name: "real,manualparent,withEventListener", defaultMode: TracingModeActiveSpansRegistry, parent: true,
withEventListener: true, opts: []SpanOption{WithDetachedRecording()}},
} {
b.Run(fmt.Sprintf("opts=%s", tc.name), func(b *testing.B) {
tr := NewTracerWithOpt(ctx,
Expand All @@ -55,6 +62,9 @@ func BenchmarkTracer_StartSpanCtx(b *testing.B) {
if tc.parent {
parent = tr.StartSpan("one-off")
defer parent.Finish()
if tc.withEventListener {
parent.RegisterEventListener(&mockEventListener{})
}
numOpts++
}
opts := make([]SpanOption, numOpts)
Expand Down Expand Up @@ -106,19 +116,38 @@ func BenchmarkSpan_GetRecording(b *testing.B) {

func BenchmarkRecordingWithStructuredEvent(b *testing.B) {
skip.UnderDeadlock(b, "span reuse triggers false-positives in the deadlock detector")
tr := NewTracerWithOpt(context.Background(),
WithTracingMode(TracingModeActiveSpansRegistry),
WithSpanReusePercent(100))

ev := &types.Int32Value{Value: 5}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
root := tr.StartSpan("foo", WithRecording(RecordingStructured))
root.RecordStructured(ev)
child := tr.StartSpan("bar", WithParent(root))
child.RecordStructured(ev)
child.Finish()
_ = root.FinishAndGetRecording(RecordingStructured)
mockListener := mockEventListener{}

for _, tc := range []struct {
name string
withEventListener bool
}{
{name: "with-event-listener", withEventListener: true},
{name: "without-event-listener"},
} {
b.Run(tc.name, func(b *testing.B) {
tr := NewTracerWithOpt(context.Background(),
WithTracingMode(TracingModeActiveSpansRegistry),
WithSpanReusePercent(100))

b.ReportAllocs()
for i := 0; i < b.N; i++ {
root := tr.StartSpan("foo", WithRecording(RecordingStructured))
// Register an event listener with the root span.
if tc.withEventListener {
root.RegisterEventListener(&mockListener)
}

root.RecordStructured(ev)

// The child span will also inherit the root span's event listener.
child := tr.StartSpan("bar", WithParent(root))
child.RecordStructured(ev)
child.Finish()
_ = root.FinishAndGetRecording(RecordingStructured)
}
})
}
}

Expand Down

0 comments on commit a40901a

Please sign in to comment.