| 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 | |
| 5 | // Package core provides support for event based telemetry. |
| 6 | package corescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/ |
| 7 | |
| 8 | import ( |
| 9 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 10 | "iterscip-go gomod github.com/golang/go/src go1.25.0 iter/" |
| 11 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 12 | |
| 13 | "golang.org/x/tools/internal/event/labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/" |
| 14 | ) |
| 15 | |
| 16 | // Event holds the information about an event of note that occurred. |
| 17 | type Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event# struct { |
| 18 | atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#at. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# |
| 19 | |
| 20 | // As events are often on the stack, storing the first few labels directly |
| 21 | // in the event can avoid an allocation at all for the very common cases of |
| 22 | // simple events. |
| 23 | // The length needs to be large enough to cope with the majority of events |
| 24 | // but no so large as to cause undue stack pressure. |
| 25 | // A log message with two values will use 3 labels (one for each value and |
| 26 | // one for the message itself). |
| 27 | |
| 28 | staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static. [3]labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label# // inline storage for the first few labels |
| 29 | dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic. []labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label# // dynamically sized storage for remaining labels |
| 30 | } |
| 31 | |
| 32 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#At().() timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time# { return ev.atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#at. } |
| 33 | |
| 34 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Formatscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Format().(f fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Statescip-go gomod github.com/golang/go/src go1.25.0 fmt/State#, r rune) { |
| 35 | if !ev.atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#at..IsZeroscip-go gomod github.com/golang/go/src go1.25.0 time/Time#IsZero().() { |
| 36 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprint().(f, ev.atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#at..Formatscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Format().("2006/01/02 15:04:05 ")) |
| 37 | } |
| 38 | for l := range ev.Labelsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Labels().() { |
| 39 | fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(f, "\n\t%v", l) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Valid().(index int) bool { |
| 44 | return index >= 0 && index < len(ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static.)+len(ev.dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic.) |
| 45 | } |
| 46 | |
| 47 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Label().(index int) labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label# { |
| 48 | if index < len(ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static.) { |
| 49 | return ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static.[index] |
| 50 | } |
| 51 | return ev.dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic.[index-len(ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static.)] |
| 52 | } |
| 53 | |
| 54 | // Labels returns an iterator over the event's valid labels. |
| 55 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Labelsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Labels().() iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#] { |
| 56 | return func(yield func(labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#) bool) { |
| 57 | for _, l := range ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static. { |
| 58 | if l.Validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Valid().() && !yield(l) { |
| 59 | return |
| 60 | } |
| 61 | } |
| 62 | for _, l := range ev.dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic. { |
| 63 | if l.Validscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Valid().() && !yield(l) { |
| 64 | return |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func (ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#) Findscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#Find().(key labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Key#) labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label# { |
| 71 | for _, l := range ev.staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static. { |
| 72 | if l.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Key().() == key { |
| 73 | return l |
| 74 | } |
| 75 | } |
| 76 | for _, l := range ev.dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic. { |
| 77 | if l.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#Key().() == key { |
| 78 | return l |
| 79 | } |
| 80 | } |
| 81 | return labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#{} |
| 82 | } |
| 83 | |
| 84 | func MakeEventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/MakeEvent().(static [3]labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#, labels []labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/.Labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/label`/Label#) Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event# { |
| 85 | return Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#{ |
| 86 | staticscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#static.: static, |
| 87 | dynamicscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#dynamic.: labels, |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // CloneEvent event returns a copy of the event with the time adjusted to at. |
| 92 | func CloneEventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/CloneEvent().(ev Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#, at timescip-go gomod github.com/golang/go/src go1.25.0 time/.Timescip-go gomod github.com/golang/go/src go1.25.0 time/Time#) Eventscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event# { |
| 93 | ev.atscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/core`/Event#at. = at |
| 94 | return ev |
| 95 | } |