traceparser

package
v0.0.0-...-c8b2ac6 Latest Latest
Warning

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

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

Documentation

Overview

Package traceparser parses the trace files produced by runtime.StartTrace

Index

Constants

View Source
const (
	FakeP    = 1000000 + iota
	TimerP   // depicts timer unblocks
	NetpollP // depicts network unblocks
	SyscallP // depicts returns from syscalls
	GCP      // depicts GC state
)

Special P identifiers.

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

Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.

Variables

View Source
var EventDescriptions = [EvCount]struct {
	Name       string
	MinVersion int
	Stack      bool
	Args       []string
	SArgs      []string // string arguments
}{
	EvNone:              {"None", 1005, false, []string{}, nil},
	EvBatch:             {"Batch", 1005, false, []string{"p", "ticks"}, nil},
	EvFrequency:         {"Frequency", 1005, false, []string{"freq"}, nil},
	EvStack:             {"Stack", 1005, false, []string{"id", "siz"}, nil},
	EvGomaxprocs:        {"Gomaxprocs", 1005, true, []string{"procs"}, nil},
	EvProcStart:         {"ProcStart", 1005, false, []string{"thread"}, nil},
	EvProcStop:          {"ProcStop", 1005, false, []string{}, nil},
	EvGCStart:           {"GCStart", 1005, true, []string{"seq"}, nil},
	EvGCDone:            {"GCDone", 1005, false, []string{}, nil},
	EvGCSTWStart:        {"GCSTWStart", 1005, false, []string{"kindid"}, []string{"kind"}},
	EvGCSTWDone:         {"GCSTWDone", 1005, false, []string{}, nil},
	EvGCSweepStart:      {"GCSweepStart", 1005, true, []string{}, nil},
	EvGCSweepDone:       {"GCSweepDone", 1005, false, []string{"swept", "reclaimed"}, nil},
	EvGoCreate:          {"GoCreate", 1005, true, []string{"g", "stack"}, nil},
	EvGoStart:           {"GoStart", 1005, false, []string{"g", "seq"}, nil},
	EvGoEnd:             {"GoEnd", 1005, false, []string{}, nil},
	EvGoStop:            {"GoStop", 1005, true, []string{}, nil},
	EvGoSched:           {"GoSched", 1005, true, []string{}, nil},
	EvGoPreempt:         {"GoPreempt", 1005, true, []string{}, nil},
	EvGoSleep:           {"GoSleep", 1005, true, []string{}, nil},
	EvGoBlock:           {"GoBlock", 1005, true, []string{}, nil},
	EvGoUnblock:         {"GoUnblock", 1005, true, []string{"g", "seq"}, nil},
	EvGoBlockSend:       {"GoBlockSend", 1005, true, []string{}, nil},
	EvGoBlockRecv:       {"GoBlockRecv", 1005, true, []string{}, nil},
	EvGoBlockSelect:     {"GoBlockSelect", 1005, true, []string{}, nil},
	EvGoBlockSync:       {"GoBlockSync", 1005, true, []string{}, nil},
	EvGoBlockCond:       {"GoBlockCond", 1005, true, []string{}, nil},
	EvGoBlockNet:        {"GoBlockNet", 1005, true, []string{}, nil},
	EvGoSysCall:         {"GoSysCall", 1005, true, []string{}, nil},
	EvGoSysExit:         {"GoSysExit", 1005, false, []string{"g", "seq", "ts"}, nil},
	EvGoSysBlock:        {"GoSysBlock", 1005, false, []string{}, nil},
	EvGoWaiting:         {"GoWaiting", 1005, false, []string{"g"}, nil},
	EvGoInSyscall:       {"GoInSyscall", 1005, false, []string{"g"}, nil},
	EvHeapAlloc:         {"HeapAlloc", 1005, false, []string{"mem"}, nil},
	EvNextGC:            {"NextGC", 1005, false, []string{"mem"}, nil},
	EvTimerGoroutine:    {"TimerGoroutine", 1005, false, []string{"g"}, nil},
	EvFutileWakeup:      {"FutileWakeup", 1005, false, []string{}, nil},
	EvString:            {"String", 1007, false, []string{}, nil},
	EvGoStartLocal:      {"GoStartLocal", 1007, false, []string{"g"}, nil},
	EvGoUnblockLocal:    {"GoUnblockLocal", 1007, true, []string{"g"}, nil},
	EvGoSysExitLocal:    {"GoSysExitLocal", 1007, false, []string{"g", "ts"}, nil},
	EvGoStartLabel:      {"GoStartLabel", 1008, false, []string{"g", "seq", "labelid"}, []string{"label"}},
	EvGoBlockGC:         {"GoBlockGC", 1008, true, []string{}, nil},
	EvGCMarkAssistStart: {"GCMarkAssistStart", 1009, true, []string{}, nil},
	EvGCMarkAssistDone:  {"GCMarkAssistDone", 1009, false, []string{}, nil},
	EvUserTaskCreate:    {"UserTaskCreate", 1011, true, []string{"taskid", "pid", "typeid"}, []string{"name"}},
	EvUserTaskEnd:       {"UserTaskEnd", 1011, true, []string{"taskid"}, nil},
	EvUserRegion:        {"UserRegion", 1011, true, []string{"taskid", "mode", "typeid"}, []string{"name"}},
	EvUserLog:           {"UserLog", 1011, true, []string{"id", "keyid"}, []string{"category", "message"}},
}

EventDescriptions describe the Events

Functions

This section is empty.

Types

type Event

type Event struct {
	Type  byte
	P     int32
	Ts    int64
	G     uint64
	StkID uint32 // key to Parsed.Stacks
	Args  [3]uint64
	SArgs []string // EvUserLog has 2. Others are 1 or none
	Link  *Event
}

An Event is the parsed form of a single trace event

func (*Event) String

func (ev *Event) String() string

type Frame

type Frame struct {
	PC   uint64
	Fn   string
	File string
	Line int
}

Frame is a frame in a stack traces

type GDesc

type GDesc struct {
	ID           uint64
	Name         string
	PC           uint64
	CreationTime int64
	StartTime    int64
	EndTime      int64

	// List of regions in the goroutine, sorted based on the start time.
	Regions []*UserRegionDesc

	// Statistics of execution time during the goroutine execution.
	GExecutionStat
	// contains filtered or unexported fields
}

GDesc contains statistics and execution details of a single goroutine.

type GExecutionStat

type GExecutionStat struct {
	ExecTime      int64
	SchedWaitTime int64
	IOTime        int64
	BlockTime     int64
	SyscallTime   int64
	GCTime        int64
	SweepTime     int64
	TotalTime     int64
}

GExecutionStat contains statistics about a goroutine's execution during a period of time.

type ParseError

type ParseError struct {
	P   *Parsed
	Err error
}

ParseError may be returned by New() or ParseBuffer() to make available some information in the case that the raw trace file seems to contain negative time stamps. (In P, Name, Size, count, Strings, Stacks, Versions are valid, and MaxTs or TicksPerSec is negative.)

func (ParseError) Error

func (pe ParseError) Error() string

type Parsed

type Parsed struct {
	// Set by New
	Name        string // File's name
	Size        int64  // File's size
	Count       int64  // approximate number of all events
	MaxTs       int64  // range of all events, in nanoseconds
	Strings     map[uint64]string
	Stacks      map[uint32][]*Frame
	Version     int   // version of the trace file from header
	TicksPerSec int64 // from EvFrequency in trailer

	// the following are per Parse
	MinWant, MaxWant int64    // range wanted, from the arguments to Parse()
	Err              error    // set by internal functions to stop further processing
	Events           []*Event // after Parse, the events from MinWant to MaxWant
	Preflen          int      // how long a prefix we added
	Ignored          int      // how many events we elided
	Added            int      // how many events we added, not including the prefix
	// contains filtered or unexported fields
}

Parsed is the result of parsing a trace file

func New

func New(fname string) (*Parsed, error)

New scans the trace file, finding the number of events, the earliest and latest timestamps, and the stacks and strings referenced in the file.

func ParseBuffer

func ParseBuffer(rd io.Reader) (*Parsed, error)

ParseBuffer treats its argument as a trace file, and returns the result of parsing it

func (*Parsed) Close

func (p *Parsed) Close() error

Close the underlying file.

func (*Parsed) GoroutineStats

func (p *Parsed) GoroutineStats() map[uint64]*GDesc

GoroutineStats generates statistics for all goroutines in the trace segment.

func (*Parsed) OSStats

func (p *Parsed) OSStats() filebuf.Stat

OSStats reports on the underlying i/o. If p was created by New, the fields report filesystem activity. If p was created by ParseBuffer, only Size is set.

func (*Parsed) Parse

func (p *Parsed) Parse(start, length int64, f func(string)) error

Parse parses the events in the interval: start <= ts <= start+length. f, if not nil, will be called at various stages of the parse, each identified by the string argument. It could report on elapsed time, or memory usage, or whatever the user wants. The number of times it is called and the contents of the string argument are both changeable details of the implementation. Parse is not safe for concurrent use.

func (*Parsed) RelatedGoroutines

func (p *Parsed) RelatedGoroutines(goid uint64) map[uint64]bool

RelatedGoroutines finds a set of goroutines related to goroutine goid.

func (*Parsed) String

func (p *Parsed) String() string

type UserRegionDesc

type UserRegionDesc struct {
	TaskID uint64
	Name   string

	// Region start event. Normally EvUserRegion start event or nil,
	// but can be EvGoCreate event if the region is a synthetic
	// region representing task inheritance from the parent goroutine.
	Start *Event

	// Region end event. Normally EvUserRegion end event or nil,
	// but can be EvGoStop or EvGoEnd event if the goroutine
	// terminated without explicitely ending the region.
	End *Event

	GExecutionStat
}

UserRegionDesc represents a region and goroutine execution stats while the region was active.

type Writer

type Writer struct {
	bytes.Buffer
}

Writer is a test trace writer.

func NewWriter

func NewWriter() *Writer

NewWriter provides the test Writer

func (*Writer) Emit

func (w *Writer) Emit(typ byte, args ...uint64)

Emit writes an event record to the trace. See Event types for valid types and required arguments.

Directories

Path Synopsis
Package filebuf implements io.SeekReader for os files.
Package filebuf implements io.SeekReader for os files.

Jump to

Keyboard shortcuts

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