golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/internal/raw/event.go (about) 1 // Copyright 2023 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 // Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT. 6 7 //go:build go1.21 8 9 package raw 10 11 import ( 12 "strconv" 13 "strings" 14 15 "golang.org/x/exp/trace/internal/event" 16 "golang.org/x/exp/trace/internal/version" 17 ) 18 19 // Event is a simple representation of a trace event. 20 // 21 // Note that this typically includes much more than just 22 // timestamped events, and it also represents parts of the 23 // trace format's framing. (But not interpreted.) 24 type Event struct { 25 Version version.Version 26 Ev event.Type 27 Args []uint64 28 Data []byte 29 } 30 31 // String returns the canonical string representation of the event. 32 // 33 // This format is the same format that is parsed by the TextReader 34 // and emitted by the TextWriter. 35 func (e *Event) String() string { 36 spec := e.Version.Specs()[e.Ev] 37 38 var s strings.Builder 39 s.WriteString(spec.Name) 40 for i := range spec.Args { 41 s.WriteString(" ") 42 s.WriteString(spec.Args[i]) 43 s.WriteString("=") 44 s.WriteString(strconv.FormatUint(e.Args[i], 10)) 45 } 46 if spec.IsStack { 47 frames := e.Args[len(spec.Args):] 48 for i := 0; i < len(frames); i++ { 49 if i%4 == 0 { 50 s.WriteString("\n\t") 51 } else { 52 s.WriteString(" ") 53 } 54 s.WriteString(frameFields[i%4]) 55 s.WriteString("=") 56 s.WriteString(strconv.FormatUint(frames[i], 10)) 57 } 58 } 59 if e.Data != nil { 60 s.WriteString("\n\tdata=") 61 s.WriteString(strconv.Quote(string(e.Data))) 62 } 63 return s.String() 64 }