internal/telemetry: add a noop exporter benchmark

This has the exporter registered but doing nothing, to measure the basic cost of
having any exporter without any specific exporter costs.
Specifically at the moment this measures the cost of filling in the time on the
event and building the TagMap that is passed down.

Change-Id: Iaae5659e3de9b871dc281c509fa2ee9c3e1d049a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226357
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Ian Cottrell 2020-03-30 07:55:16 -04:00
parent 80f63e2b9b
commit 4edcf52965
1 changed files with 9 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package telemetry_test
import (
"context"
"io/ioutil"
"log"
"testing"
@ -107,6 +108,11 @@ func Benchmark(b *testing.B) {
}
event.SetExporter(noopExporter)
for _, t := range benchmarks {
b.Run(t.name+"Noop", t.test)
}
event.SetExporter(export.Spans(export.LogWriter(ioutil.Discard, false)))
for _, t := range benchmarks {
b.Run(t.name, t.test)
}
@ -137,13 +143,9 @@ func (hooks Hooks) runBenchmark(b *testing.B) {
}
func init() {
log.SetOutput(new(noopWriter))
log.SetOutput(ioutil.Discard)
}
type noopWriter int
func (nw *noopWriter) Write(b []byte) (int, error) {
return len(b), nil
func noopExporter(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context {
return ctx
}
var noopExporter = export.Spans(export.LogWriter(new(noopWriter), false))