1
0
mirror of https://github.com/golang/go synced 2024-11-06 03:26:15 -07:00
go/internal/telemetry/event/trace.go

44 lines
1.7 KiB
Go
Raw Normal View History

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package event
import (
"context"
)
internal/telemetry: add fast non variadic event functions This adds variants of the main event functions that take specific numbers of tags, rather than a tag slice. This reduces the allocation cost when using those functions with no exporter to zero. name old time/op new time/op delta /Baseline-8 158ns ± 7% 154ns ± 1% ~ /StdLog-8 6.90µs ± 1% 6.83µs ± 1% ~ /LogNoExporter-8 1.78µs ± 5% 1.20µs ± 3% -32.37% /TraceNoExporter-8 3.11µs ± 3% 2.48µs ± 2% -20.39% /StatsNoExporter-8 3.18µs ± 5% 1.87µs ± 3% -41.16% /Log-8 46.8µs ± 2% 44.8µs ± 1% -4.33% /Trace-8 55.1µs ± 5% 54.3µs ± 3% ~ /Stats-8 15.8µs ± 3% 13.4µs ± 1% -15.00% name old alloc/op new alloc/op delta /Baseline-8 0.00B 0.00B ~ /StdLog-8 552B ± 0% 552B ± 0% ~ /LogNoExporter-8 1.02kB ± 0% 0.00kB -100.00% /TraceNoExporter-8 1.54kB ± 0% 0.51kB ± 0% -66.67% /StatsNoExporter-8 2.05kB ± 0% 0.00kB -100.00% /Log-8 26.0kB ± 0% 24.0kB ± 0% -7.87% /Trace-8 28.7kB ± 0% 27.1kB ± 0% ~ /Stats-8 13.3kB ± 0% 10.2kB ± 0% -23.08% name old allocs/op new allocs/op delta /Baseline-8 0.00 0.00 ~ /StdLog-8 30.0 ± 0% 30.0 ± 0% ~ /LogNoExporter-8 16.0 ± 0% 0.0 -100.00% /TraceNoExporter-8 32.0 ± 0% 16.0 ± 0% -50.00% /StatsNoExporter-8 32.0 ± 0% 0.0 -100.00% /Log-8 430 ± 0% 382 ± 0% -11.16% /Trace-8 496 ± 0% 464 ± 0% -6.45% /Stats-8 192 ± 0% 128 ± 0% -33.33% Change-Id: I629c0d506ab07de6f12b0acbecfc7407f59a4285 Reviewed-on: https://go-review.googlesource.com/c/tools/+/225580 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-25 20:50:00 -06:00
// StartSpan sends a span start event with the supplied tag list to the exporter.
// It also returns a function that will end the span, which should normally be
// deferred.
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name)}, tags))
return ctx, func() { dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil)) }
}
internal/telemetry: add fast non variadic event functions This adds variants of the main event functions that take specific numbers of tags, rather than a tag slice. This reduces the allocation cost when using those functions with no exporter to zero. name old time/op new time/op delta /Baseline-8 158ns ± 7% 154ns ± 1% ~ /StdLog-8 6.90µs ± 1% 6.83µs ± 1% ~ /LogNoExporter-8 1.78µs ± 5% 1.20µs ± 3% -32.37% /TraceNoExporter-8 3.11µs ± 3% 2.48µs ± 2% -20.39% /StatsNoExporter-8 3.18µs ± 5% 1.87µs ± 3% -41.16% /Log-8 46.8µs ± 2% 44.8µs ± 1% -4.33% /Trace-8 55.1µs ± 5% 54.3µs ± 3% ~ /Stats-8 15.8µs ± 3% 13.4µs ± 1% -15.00% name old alloc/op new alloc/op delta /Baseline-8 0.00B 0.00B ~ /StdLog-8 552B ± 0% 552B ± 0% ~ /LogNoExporter-8 1.02kB ± 0% 0.00kB -100.00% /TraceNoExporter-8 1.54kB ± 0% 0.51kB ± 0% -66.67% /StatsNoExporter-8 2.05kB ± 0% 0.00kB -100.00% /Log-8 26.0kB ± 0% 24.0kB ± 0% -7.87% /Trace-8 28.7kB ± 0% 27.1kB ± 0% ~ /Stats-8 13.3kB ± 0% 10.2kB ± 0% -23.08% name old allocs/op new allocs/op delta /Baseline-8 0.00 0.00 ~ /StdLog-8 30.0 ± 0% 30.0 ± 0% ~ /LogNoExporter-8 16.0 ± 0% 0.0 -100.00% /TraceNoExporter-8 32.0 ± 0% 16.0 ± 0% -50.00% /StatsNoExporter-8 32.0 ± 0% 0.0 -100.00% /Log-8 430 ± 0% 382 ± 0% -11.16% /Trace-8 496 ± 0% 464 ± 0% -6.45% /Stats-8 192 ± 0% 128 ± 0% -33.33% Change-Id: I629c0d506ab07de6f12b0acbecfc7407f59a4285 Reviewed-on: https://go-review.googlesource.com/c/tools/+/225580 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-25 20:50:00 -06:00
// StartSpan1 sends a span start event with the supplied tag list to the exporter.
// It also returns a function that will end the span, which should normally be
// deferred.
func StartSpan1(ctx context.Context, name string, t1 Tag) (context.Context, func()) {
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name), t1}, nil))
return ctx, func() {
dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil))
}
}
// StartSpan2 sends a span start event with the supplied tag list to the exporter.
// It also returns a function that will end the span, which should normally be
// deferred.
func StartSpan2(ctx context.Context, name string, t1, t2 Tag) (context.Context, func()) {
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name), t1, t2}, nil))
return ctx, func() {
dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil))
}
}
// Detach returns a context without an associated span.
// This allows the creation of spans that are not children of the current span.
func Detach(ctx context.Context) context.Context {
return dispatch(ctx, makeEvent(DetachType, sTags{}, nil))
}