Documentation
¶
Overview ¶
Package trace provides Chrome Trace Event format instrumentation for the Kite engine. Events are captured as a simple event list and written as a JSON array consumable by chrome://tracing.
Tracer ¶
Tracer captures named trace events with microsecond timestamps. Each event is a pair of Begin/End markers that chrome://tracing renders as a horizontal bar on a timeline.
Usage ¶
The Begin method returns a cleanup function suitable for defer:
tracer := trace.NewTracer()
defer tracer.WriteJSON(os.Stdout)
func() {
defer tracer.Begin("Layout")()
// ... layout work ...
}()
BeginThread(name, tid) scopes events to a specific thread ID. BeginWithArgs(name, args) attaches a map of additional arguments.
Nil Safety ¶
On a nil *Tracer, Begin and its variants return a no-op function, and WriteJSON returns nil without writing.
Index ¶
- func Noop() func()
- type Event
- type EventType
- type Tracer
- func (t *Tracer) Begin(name string) func()
- func (t *Tracer) BeginThread(name string, tid int) func()
- func (t *Tracer) BeginThreadWithArgs(name string, tid int, args map[string]any) func()
- func (t *Tracer) BeginWithArgs(name string, args map[string]any) func()
- func (t *Tracer) WriteJSON(w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Name string `json:"name"`
Ph EventType `json:"ph"`
TS int64 `json:"ts"` // Microseconds
Pid int `json:"pid"`
Tid int `json:"tid"`
Args map[string]any `json:"args,omitempty"`
}
Event represents a single Chrome Trace Event.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer captures trace events and formats them for Chrome Trace Viewer.
func (*Tracer) Begin ¶
Begin starts a new synchronous trace event. It returns a function that, when called, records the end of the event.
Usage: defer tracer.Begin("Layout")()
func (*Tracer) BeginThread ¶
BeginThread starts a new synchronous trace event on a specific thread. It returns a function that, when called, records the end of the event.
func (*Tracer) BeginThreadWithArgs ¶
BeginThreadWithArgs starts a new synchronous trace event on a specific thread with optional arguments.
func (*Tracer) BeginWithArgs ¶
BeginWithArgs starts a new synchronous trace event with optional arguments.