event

package
v0.0.0-...-dc4a015 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2017 License: BSD-3-Clause, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArgTimestamp      = `Timestamp`
	ArgRealTimestamp  = `RealTimestamp`
	ArgFrequency      = `Frequency`
	ArgSequence       = `Sequence`
	ArgSequenceGC     = `SequenceGC`
	ArgStackID        = `StackID`
	ArgStackSize      = `StackSize`
	ArgNewStackID     = `NewStackID`
	ArgStringID       = `StringID`
	ArgLabelStringID  = `LabelStringID`
	ArgThreadID       = `ThreadID`
	ArgProcessorID    = `ProcessorID`
	ArgGoroutineID    = `GoroutineID`
	ArgNewGoroutineID = `NewGoroutineID`
	ArgGomaxprocs     = `Gomaxprocs`
	ArgHeapAlloc      = `HeapAlloc`
	ArgNextGC         = `NextGC`
	ArgKind           = `Kind`
)

Arguments that may exist within an event, 1 or more of these are returned from calls to the Args method of Type.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {

	// Type is the type of this Event.
	Type Type

	// Args will contain all the Event specific arguments, excluding sequences
	// and timestamps. All uleb128 values are decoded here including arbitrary
	// length events like Stack.
	Args []uint64

	// Data may be nil or a slice containing Event data for arguments that are not
	// uleb128 encoded. Currently only the string event fits this criteria.
	//
	// @TODO Remove all together in favor of storing in *Trace?
	Data []byte

	// Id's of the P and G associated with this event. With G being a goroutine
	// and P a resource that is required to execute Go code.
	P, G int64

	// Ts is the timestamp of the event.
	Ts int64

	// Off is the offset of the first byte for this Event relative to the
	// beginning of the input stream.
	Off int
}

Event provides access to trace data for the Go execution tracer.

func (*Event) Copy

func (e *Event) Copy() *Event

Copy will return a deep copy of this event.

func (*Event) Get

func (e *Event) Get(name string) uint64

Get returns a argument by name, or the zero value if it doesn't exist.

func (*Event) Lookup

func (e *Event) Lookup(name string) (arg uint64, found bool)

Lookup returns the arg and a boolean true, or zero value and false if arg does not exist in this event type.

func (*Event) Reset

func (e *Event) Reset()

Reset will reset this event for reuse.

func (Event) String

func (e Event) String() string

String implements fmt.Stringer by returning a helpful string describing this event type.

type Frame

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

Frame is a single frame within an stack trace.

func (Frame) File

func (f Frame) File() string

File of this frame.

func (Frame) Func

func (f Frame) Func() string

Func is the enclosing function of this frame.

func (Frame) Line

func (f Frame) Line() int

Line of this frame.

func (Frame) PC

func (f Frame) PC() uint64

PC is the program counter of this frame.

func (Frame) String

func (f Frame) String() string

Strings implements fmt.Stringer.

type Stack

type Stack []Frame

Stack is a slice of Frame.

func (Stack) Empty

func (s Stack) Empty() bool

Empty reports if the current stack is empty.

func (Stack) String

func (s Stack) String() string

Strings implements fmt.Stringer.

type Trace

type Trace struct {
	Version Version
	Strings map[uint64]string
	Stacks  map[uint64]Stack
	Count   int
	// contains filtered or unexported fields
}

Trace maintains the shared satate across events.

func NewTrace

func NewTrace(v Version) (*Trace, error)

NewTrace will create a new trace for the given version, or return an error if the version is unknown.

func (*Trace) Reset

func (tr *Trace) Reset()

Reset will reset this event for reuse.

func (*Trace) Stack

func (tr *Trace) Stack(evt *Event) (Stack, error)

Stack returns the Stack trace associated with the given event, if any. It's possible that events which should have a stack are the zero value for one o two reasons, the stack event was not yet sent over the wire or the Stack was omitted entirely by the runtime. Stacks may be shared across multiple events and should not be mutated, make a copy instead. This will not retrieve the new stack of a EvCreate event, you may use e.Get(ArgNewStackID) tr.Stacks for that.

func (*Trace) Visit

func (tr *Trace) Visit(evt *Event) (err error)

Visit the given event with this Trace.

type Type

type Type byte

Type represents the type of trace event.

const (
	EvNone              Type = 0  // unused
	EvBatch             Type = 1  // start of per-P batch of events [pid, timestamp]
	EvFrequency         Type = 2  // contains tracer timer frequency [frequency (ticks per second)]
	EvStack             Type = 3  // stack [stack id, number of PCs, array of {PC, func string ID, file string ID, line}]
	EvGomaxprocs        Type = 4  // current value of GOMAXPROCS [timestamp, GOMAXPROCS, stack id]
	EvProcStart         Type = 5  // start of P [timestamp, thread id]
	EvProcStop          Type = 6  // stop of P [timestamp]
	EvGCStart           Type = 7  // GC start [timestamp, seq, stack id]
	EvGCDone            Type = 8  // GC done [timestamp]
	EvGCSTWStart        Type = 9  // GC mark termination start [timestamp, kind]
	EvGCSTWDone         Type = 10 // GC mark termination done [timestamp]
	EvGCSweepStart      Type = 11 // GC sweep start [timestamp, stack id]
	EvGCSweepDone       Type = 12 // GC sweep done [timestamp]
	EvGoCreate          Type = 13 // goroutine creation [timestamp, new goroutine id, new stack id, stack id]
	EvGoStart           Type = 14 // goroutine starts running [timestamp, goroutine id, seq]
	EvGoEnd             Type = 15 // goroutine ends [timestamp]
	EvGoStop            Type = 16 // goroutine stops (like in select{}) [timestamp, stack]
	EvGoSched           Type = 17 // goroutine calls Gosched [timestamp, stack]
	EvGoPreempt         Type = 18 // goroutine is preempted [timestamp, stack]
	EvGoSleep           Type = 19 // goroutine calls Sleep [timestamp, stack]
	EvGoBlock           Type = 20 // goroutine blocks [timestamp, stack]
	EvGoUnblock         Type = 21 // goroutine is unblocked [timestamp, goroutine id, seq, stack]
	EvGoBlockSend       Type = 22 // goroutine blocks on chan send [timestamp, stack]
	EvGoBlockRecv       Type = 23 // goroutine blocks on chan recv [timestamp, stack]
	EvGoBlockSelect     Type = 24 // goroutine blocks on select [timestamp, stack]
	EvGoBlockSync       Type = 25 // goroutine blocks on Mutex/RWMutex [timestamp, stack]
	EvGoBlockCond       Type = 26 // goroutine blocks on Cond [timestamp, stack]
	EvGoBlockNet        Type = 27 // goroutine blocks on network [timestamp, stack]
	EvGoSysCall         Type = 28 // syscall enter [timestamp, stack]
	EvGoSysExit         Type = 29 // syscall exit [timestamp, goroutine id, seq, real timestamp]
	EvGoSysBlock        Type = 30 // syscall blocks [timestamp]
	EvGoWaiting         Type = 31 // denotes that goroutine is blocked when tracing starts [timestamp, goroutine id]
	EvGoInSyscall       Type = 32 // denotes that goroutine is in syscall when tracing starts [timestamp, goroutine id]
	EvHeapAlloc         Type = 33 // memstats.heap_live change [timestamp, heap_alloc]
	EvNextGC            Type = 34 // memstats.next_gc change [timestamp, next_gc]
	EvTimerGoroutine    Type = 35 // denotes timer goroutine [timer goroutine id]
	EvFutileWakeup      Type = 36 // denotes that the previous wakeup of this goroutine was futile [timestamp]
	EvString            Type = 37 // string dictionary entry [ID, length, string]
	EvGoStartLocal      Type = 38 // goroutine starts running on the same P as the last event [timestamp, goroutine id]
	EvGoUnblockLocal    Type = 39 // goroutine is unblocked on the same P as the last event [timestamp, goroutine id, stack]
	EvGoSysExitLocal    Type = 40 // syscall exit on the same P as the last event [timestamp, goroutine id, real timestamp]
	EvGoStartLabel      Type = 41 // goroutine starts running with label [timestamp, goroutine id, seq, label string id]
	EvGoBlockGC         Type = 42 // goroutine blocks on GC assist [timestamp, stack]
	EvGCMarkAssistStart Type = 43 // GC mark assist start [timestamp, stack]
	EvGCMarkAssistDone  Type = 44 // GC mark assist done [timestamp]
	EvCount             Type = 45
)

These are the types of events that may be emitted. They are copied directly from the runtime/trace.go source file.

func (Type) Arg

func (t Type) Arg(name string) (arg int, found bool)

Arg returns the arg index and a boolean true, or -1 and false if arg does not exist in this event type.

func (Type) Args

func (t Type) Args() []string

Args returns an ordered list of arguments this type of event will contain.

func (Type) Name

func (t Type) Name() string

Name returns the name of this event type.

func (Type) Since

func (t Type) Since() Version

Since returns the version that this event was introduced.

func (Type) String

func (t Type) String() string

String implements fmt.Stringer by returning a helpful string describing this event type.

func (Type) Valid

func (t Type) Valid() bool

Valid returns true if the event Type is valid, false otherwise.

type Version

type Version byte

Version of Go declared in the header of the trace. Each version is represented in constant declarations with comments mentioning the associated Go version.

const (

	// Version1 was released in Go version 1.5 - 2015/08/19
	Version1 Version = 1

	// Version2 was released in Go version 1.7 - 2016/08/15
	Version2 Version = 2

	// Version3 was released in Go version 1.8 - 2017/02/16
	Version3 Version = 3

	// Version4 is in tip, currently marked in the header as 1.9.
	Version4 Version = 4

	// Latest always points to the newest released version for convenience.
	Latest = Version4
)

func (Version) Go

func (v Version) Go() string

Go returns the version of Go this version was released with.

func (Version) String

func (v Version) String() string

String implements fmt.Stringer.

func (Version) Types

func (v Version) Types() []Type

Types returns this versions declared event types. The arguments declared by each Type will always have the latest versions signature. The returned value must not be mutated and may be nil if the Version is invalid.

func (Version) Valid

func (v Version) Valid() bool

Valid returns true if this version object is from a valid trace header, false otherwise.

type Visitor

type Visitor interface {
	Visit(evt *Event) error
}

Visitor is the interface that wraps the basic Visit method.

Implementations of Visit indicate they may visit one or more events within a trace.

Jump to

Keyboard shortcuts

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