trace

Imports

Imports #

"context"
"encoding/json"
"errors"
"internal/trace/traceviewer/format"
"os"
"strings"
"sync/atomic"
"time"

Constants & Variables

bindEnclosingSlice const #

Constants used in event fields. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for more details.

const bindEnclosingSlice = "e"

phaseDurationBegin const #

Constants used in event fields. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for more details.

const phaseDurationBegin = "B"

phaseDurationEnd const #

Constants used in event fields. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for more details.

const phaseDurationEnd = "E"

phaseFlowEnd const #

Constants used in event fields. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for more details.

const phaseFlowEnd = "f"

phaseFlowStart const #

Constants used in event fields. See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU for more details.

const phaseFlowStart = "s"

traceStarted var #

var traceStarted atomic.Bool

Structs

Span struct #

type Span struct {
t *tracer
name string
tid uint64
start time.Time
end time.Time
}

traceContext struct #

type traceContext struct {
t *tracer
tid uint64
}

traceFile struct #

type traceFile struct {
f *os.File
sb *strings.Builder
enc *json.Encoder
entries int64
}

traceKey struct #

traceKey is the context key for tracing information. It is unexported to prevent collisions with context keys defined in other packages.

type traceKey struct {

}

tracer struct #

type tracer struct {
file chan traceFile
nextTID atomic.Uint64
nextFlowID atomic.Uint64
}

Functions

Close method #

func (t *tracer) Close() error

Done method #

func (s *Span) Done()

Flow function #

Flow marks a flow indicating that the 'to' span depends on the 'from' span. Flow should be called while the 'to' span is in progress.

func Flow(ctx context.Context, from *Span, to *Span)

Start function #

Start starts a trace which writes to the given file.

func Start(ctx context.Context, file string) (context.Context, func() error, error)

StartGoroutine function #

StartGoroutine associates the context with a new Thread ID. The Chrome trace viewer associates each trace event with a thread, and doesn't expect events with the same thread id to happen at the same time.

func StartGoroutine(ctx context.Context) context.Context

StartSpan function #

StartSpan starts a trace event with the given name. The Span ends when its Done method is called.

func StartSpan(ctx context.Context, name string) (context.Context, *Span)

getNextFlowID method #

func (t *tracer) getNextFlowID() uint64

getNextTID method #

func (t *tracer) getNextTID() uint64

getTraceContext function #

func getTraceContext(ctx context.Context) (traceContext, bool)

writeEvent method #

func (t *tracer) writeEvent(ev *format.Event) error

Generated with Arrow