trace

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Noop

func Noop() func()

Noop returns a function that does nothing.

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 EventType

type EventType string

EventType represents the phase of a trace event.

const (
	Begin EventType = "B"
	End   EventType = "E"
)

type Tracer

type Tracer struct {
	// contains filtered or unexported fields
}

Tracer captures trace events and formats them for Chrome Trace Viewer.

func NewTracer

func NewTracer() *Tracer

NewTracer creates a new Tracer.

func (*Tracer) Begin

func (t *Tracer) Begin(name string) func()

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

func (t *Tracer) BeginThread(name string, tid int) func()

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

func (t *Tracer) BeginThreadWithArgs(name string, tid int, args map[string]any) func()

BeginThreadWithArgs starts a new synchronous trace event on a specific thread with optional arguments.

func (*Tracer) BeginWithArgs

func (t *Tracer) BeginWithArgs(name string, args map[string]any) func()

BeginWithArgs starts a new synchronous trace event with optional arguments.

func (*Tracer) WriteJSON

func (t *Tracer) WriteJSON(w io.Writer) error

WriteJSON writes the captured events as a JSON array to w.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL