1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

internal/telemetry: add simple tracing benchmarks

These are just like the logging benchmarks but for tracing instead.
Also makes the log writer write out tracing events as well if it is
not in only errors mode

Change-Id: Ie00d7c80f7e2b9433787603261950f70ab1c1e9d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221739
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Cottrell 2020-03-01 18:46:11 -05:00
parent 3e346efd93
commit c5a1414753
2 changed files with 42 additions and 2 deletions

View File

@ -162,6 +162,33 @@ func BenchmarkLogging(b *testing.B) {
}
}
}
func BenchmarkTracingNoExporter(b *testing.B) {
ctx := context.Background()
export.SetExporter(nil)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, value := range values {
if g := A_trace(ctx, value); g <= 0 {
b.Fatalf("Unexpected got g(%d) <= 0", g)
}
}
}
}
func BenchmarkTracing(b *testing.B) {
ctx := context.Background()
export.SetExporter(newExporter())
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, value := range values {
if g := A_trace(ctx, value); g <= 0 {
b.Fatalf("Unexpected got g(%d) <= 0", g)
}
}
}
}
func BenchmarkLoggingStdlib(b *testing.B) {
ctx := context.Background()

View File

@ -25,8 +25,21 @@ type logWriter struct {
onlyErrors bool
}
func (w *logWriter) StartSpan(context.Context, *telemetry.Span) {}
func (w *logWriter) FinishSpan(context.Context, *telemetry.Span) {}
func (w *logWriter) StartSpan(ctx context.Context, span *telemetry.Span) {
if w.onlyErrors {
return
}
fmt.Fprintf(w.writer, "start: %v %v", span.Name, span.ID)
if span.ParentID.IsValid() {
fmt.Fprintf(w.writer, "[%v]", span.ParentID)
}
}
func (w *logWriter) FinishSpan(ctx context.Context, span *telemetry.Span) {
if w.onlyErrors {
return
}
fmt.Fprintf(w.writer, "finish: %v %v", span.Name, span.ID)
}
func (w *logWriter) ProcessEvent(ctx context.Context, event telemetry.Event) context.Context {
if w.onlyErrors && event.Error == nil {
return ctx