mirror of
https://github.com/golang/go
synced 2024-11-05 23:36:12 -07:00
36db529775
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>
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
// 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"
|
|
"errors"
|
|
)
|
|
|
|
// Log sends a log event with the supplied tag list to the exporter.
|
|
func Log(ctx context.Context, tags ...Tag) {
|
|
dispatch(ctx, makeEvent(LogType, sTags{}, tags))
|
|
}
|
|
|
|
// Log1 sends a label event to the exporter with the supplied tags.
|
|
func Log1(ctx context.Context, t1 Tag) context.Context {
|
|
return dispatch(ctx, makeEvent(LogType, sTags{t1}, nil))
|
|
}
|
|
|
|
// Log2 sends a label event to the exporter with the supplied tags.
|
|
func Log2(ctx context.Context, t1, t2 Tag) context.Context {
|
|
return dispatch(ctx, makeEvent(LogType, sTags{t1, t2}, nil))
|
|
}
|
|
|
|
// Log3 sends a label event to the exporter with the supplied tags.
|
|
func Log3(ctx context.Context, t1, t2, t3 Tag) context.Context {
|
|
return dispatch(ctx, makeEvent(LogType, sTags{t1, t2, t3}, nil))
|
|
}
|
|
|
|
// Print takes a message and a tag list and combines them into a single event
|
|
// before delivering them to the exporter.
|
|
func Print(ctx context.Context, message string, tags ...Tag) {
|
|
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message)}, tags))
|
|
}
|
|
|
|
// Print1 takes a message and one tag delivers a log event to the exporter.
|
|
// It is a customized version of Print that is faster and does no allocation.
|
|
func Print1(ctx context.Context, message string, t1 Tag) {
|
|
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1}, nil))
|
|
}
|
|
|
|
// Print2 takes a message and two tags and delivers a log event to the exporter.
|
|
// It is a customized version of Print that is faster and does no allocation.
|
|
func Print2(ctx context.Context, message string, t1 Tag, t2 Tag) {
|
|
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), t1, t2}, nil))
|
|
}
|
|
|
|
// Error takes a message and a tag list and combines them into a single event
|
|
// before delivering them to the exporter. It captures the error in the
|
|
// delivered event.
|
|
func Error(ctx context.Context, message string, err error, tags ...Tag) {
|
|
if err == nil {
|
|
err = errors.New(message)
|
|
message = ""
|
|
}
|
|
dispatch(ctx, makeEvent(LogType, sTags{Msg.Of(message), Err.Of(err)}, tags))
|
|
}
|