1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package core 6 7import ( 8 "context" 9 10 "golang.org/x/tools/internal/event/keys" 11 "golang.org/x/tools/internal/event/label" 12) 13 14// Log1 takes a message and one label delivers a log event to the exporter. 15// It is a customized version of Print that is faster and does no allocation. 16func Log1(ctx context.Context, message string, t1 label.Label) { 17 Export(ctx, MakeEvent([3]label.Label{ 18 keys.Msg.Of(message), 19 t1, 20 }, nil)) 21} 22 23// Log2 takes a message and two labels and delivers a log event to the exporter. 24// It is a customized version of Print that is faster and does no allocation. 25func Log2(ctx context.Context, message string, t1 label.Label, t2 label.Label) { 26 Export(ctx, MakeEvent([3]label.Label{ 27 keys.Msg.Of(message), 28 t1, 29 t2, 30 }, nil)) 31} 32 33// Metric1 sends a label event to the exporter with the supplied labels. 34func Metric1(ctx context.Context, t1 label.Label) context.Context { 35 return Export(ctx, MakeEvent([3]label.Label{ 36 keys.Metric.New(), 37 t1, 38 }, nil)) 39} 40 41// Metric2 sends a label event to the exporter with the supplied labels. 42func Metric2(ctx context.Context, t1, t2 label.Label) context.Context { 43 return Export(ctx, MakeEvent([3]label.Label{ 44 keys.Metric.New(), 45 t1, 46 t2, 47 }, nil)) 48} 49 50// Start1 sends a span start event with the supplied label list to the exporter. 51// It also returns a function that will end the span, which should normally be 52// deferred. 53func Start1(ctx context.Context, name string, t1 label.Label) (context.Context, func()) { 54 return ExportPair(ctx, 55 MakeEvent([3]label.Label{ 56 keys.Start.Of(name), 57 t1, 58 }, nil), 59 MakeEvent([3]label.Label{ 60 keys.End.New(), 61 }, nil)) 62} 63 64// Start2 sends a span start event with the supplied label list to the exporter. 65// It also returns a function that will end the span, which should normally be 66// deferred. 67func Start2(ctx context.Context, name string, t1, t2 label.Label) (context.Context, func()) { 68 return ExportPair(ctx, 69 MakeEvent([3]label.Label{ 70 keys.Start.Of(name), 71 t1, 72 t2, 73 }, nil), 74 MakeEvent([3]label.Label{ 75 keys.End.New(), 76 }, nil)) 77} 78