Debian Codegraph @

trace/internal/raw/event.go

raw symbols SCIP
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; DO NOT EDIT.
6
7 //go:build go1.23
8
9 package raw
10
11 import (
12 "encoding/binary"
13 "strconv"
14 "strings"
15
16 "golang.org/x/exp/trace/internal/tracev2"
17 "golang.org/x/exp/trace/internal/version"
18 )
19
20 // Event is a simple representation of a trace event.
21 //
22 // Note that this typically includes much more than just
23 // timestamped events, and it also represents parts of the
24 // trace format's framing. (But not interpreted.)
25 type Event struct {
26 Version version.Version
27 Ev tracev2.EventType
28 Args []uint64
29 Data []byte
30 }
31
32 // String returns the canonical string representation of the event.
33 //
34 // This format is the same format that is parsed by the TextReader
35 // and emitted by the TextWriter.
36 func (e *Event) String() string {
37 spec := e.Version.Specs()[e.Ev]
38
39 var s strings.Builder
40 s.WriteString(spec.Name)
41 for i := range spec.Args {
42 s.WriteString(" ")
43 s.WriteString(spec.Args[i])
44 s.WriteString("=")
45 s.WriteString(strconv.FormatUint(e.Args[i], 10))
46 }
47 if spec.IsStack {
48 frames := e.Args[len(spec.Args):]
49 for i := 0; i < len(frames); i++ {
50 if i%4 == 0 {
51 s.WriteString("\n\t")
52 } else {
53 s.WriteString(" ")
54 }
55 s.WriteString(frameFields[i%4])
56 s.WriteString("=")
57 s.WriteString(strconv.FormatUint(frames[i], 10))
58 }
59 }
60 if e.Data != nil {
61 s.WriteString("\n\tdata=")
62 s.WriteString(strconv.Quote(string(e.Data)))
63 }
64 return s.String()
65 }
66
67 // EncodedSize returns the canonical encoded size of an event.
68 func (e *Event) EncodedSize() int {
69 size := 1
70 var buf [binary.MaxVarintLen64]byte
71 for _, arg := range e.Args {
72 size += binary.PutUvarint(buf[:], arg)
73 }
74 spec := e.Version.Specs()[e.Ev]
75 if spec.HasData {
76 size += binary.PutUvarint(buf[:], uint64(len(e.Data)))
77 size += len(e.Data)
78 }
79 return size
80 }