package trace

Import Path
	internal/trace (on golang.org and go.dev)

Dependency Relation
	imports 16 packages, and imported by 0 packages

Involved Source Files
	gc.go
	goroutines.go
	mud.go
	order.go
	parser.go
	writer.go

Exported Type Names

type Event (struct) Event describes one event in the trace. // event-type-specific arguments // G on which the event happened linked event (can be nil), depends on event type: for GCStart: the GCStop for GCSTWStart: the GCSTWDone for GCSweepStart: the GCSweepDone for GoCreate: first GoStart of the created goroutine for GoStart/GoStartLabel: the associated GoEnd, GoBlock or other blocking event for GoSched/GoPreempt: the next GoStart for GoBlock and other blocking events: the unblock event for GoUnblock: the associated GoStart for blocking GoSysCall: the associated GoSysExit for GoSysExit: the next GoStart for GCMarkAssistStart: the associated GCMarkAssistDone for UserTaskCreate: the UserTaskEnd for UserRegion: if the start region, the corresponding UserRegion end event // offset in input file (for debugging and error reporting) // P on which the event happened (can be one of TimerP, NetpollP, SyscallP) // event-type-specific string args // stack trace (can be empty) // unique stack ID // timestamp in nanoseconds // one of Ev* (*T) String() string *T : expvar.Var *T : fmt.Stringer func GoroutineStats(events []*Event) map[uint64]*GDesc func MutatorUtilization(events []*Event, flags UtilFlags) [][]MutatorUtil func Print(events []*Event) func PrintEvent(ev *Event) func RelatedGoroutines(events []*Event, goid uint64) map[uint64]bool
type Frame (struct) Frame is a frame in stack traces. File string Fn string Line int PC uint64
type GDesc (struct) GDesc contains statistics and execution details of a single goroutine. CreationTime int64 EndTime int64 Statistics of execution time during the goroutine execution. GExecutionStat.BlockTime int64 GExecutionStat.ExecTime int64 GExecutionStat.GCTime int64 GExecutionStat.IOTime int64 GExecutionStat.SchedWaitTime int64 GExecutionStat.SweepTime int64 GExecutionStat.SyscallTime int64 GExecutionStat.TotalTime int64 ID uint64 Name string PC uint64 List of regions in the goroutine, sorted based on the start time. StartTime int64 func GoroutineStats(events []*Event) map[uint64]*GDesc
type GExecutionStat (struct) GExecutionStat contains statistics about a goroutine's execution during a period of time. BlockTime int64 ExecTime int64 GCTime int64 IOTime int64 SchedWaitTime int64 SweepTime int64 SyscallTime int64 TotalTime int64
type MMUCurve (struct) An MMUCurve is the minimum mutator utilization curve across multiple window sizes. Examples returns n specific examples of the lowest mutator utilization for the given window size. The returned windows will be disjoint (otherwise there would be a huge number of mostly-overlapping windows at the single lowest point). There are no guarantees on which set of disjoint windows this returns. MMU returns the minimum mutator utilization for the given time window. This is the minimum utilization for all windows of this duration across the execution. The returned value is in the range [0, 1]. MUD returns mutator utilization distribution quantiles for the given window size. The mutator utilization distribution is the distribution of mean mutator utilization across all windows of the given window size in the trace. The minimum mutator utilization is the minimum (0th percentile) of this distribution. (However, if only the minimum is desired, it's more efficient to use the MMU method.) func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve
type MutatorUtil (struct) MutatorUtil is a change in mutator utilization at a particular time. Mutator utilization functions are represented as a time-ordered []MutatorUtil. Time int64 Util is the mean mutator utilization starting at Time. This is in the range [0, 1]. func MutatorUtilization(events []*Event, flags UtilFlags) [][]MutatorUtil func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve
type ParseResult (struct) ParseResult is the result of Parse. Events is the sorted list of Events in the trace. Stacks is the stack traces keyed by stack IDs from the trace. func Parse(r io.Reader, bin string) (ParseResult, error)
type UserRegionDesc (struct) UserRegionDesc represents a region and goroutine execution stats while the region was active. Region end event. Normally EvUserRegion end event or nil, but can be EvGoStop or EvGoEnd event if the goroutine terminated without explicitly ending the region. GExecutionStat GExecutionStat GExecutionStat.BlockTime int64 GExecutionStat.ExecTime int64 GExecutionStat.GCTime int64 GExecutionStat.IOTime int64 GExecutionStat.SchedWaitTime int64 GExecutionStat.SweepTime int64 GExecutionStat.SyscallTime int64 GExecutionStat.TotalTime int64 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. TaskID uint64
type UtilFlags int UtilFlags controls the behavior of MutatorUtilization. func MutatorUtilization(events []*Event, flags UtilFlags) [][]MutatorUtil const UtilAssist const UtilBackground const UtilPerProc const UtilSTW const UtilSweep
type UtilWindow (struct) UtilWindow is a specific window at Time. MutatorUtil is the mean mutator utilization in this window. Time int64 func (*MMUCurve).Examples(window time.Duration, n int) (worst []UtilWindow)
type Writer (struct) Writer is a test trace writer. Buffer bytes.Buffer Bytes returns a slice of length b.Len() holding the unread portion of the buffer. The slice is valid for use only until the next buffer modification (that is, only until the next call to a method like Read, Write, Reset, or Truncate). The slice aliases the buffer content at least until the next buffer modification, so immediate changes to the slice will affect the result of future reads. Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data. Emit writes an event record to the trace. See Event types for valid types and required arguments. Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge. Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()). Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method. Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil. ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF. ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim. ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge. ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1. ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim. Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0). String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>". To build strings more efficiently, see the strings.Builder type. Truncate discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It panics if n is negative or greater than the length of the buffer. UnreadByte unreads the last byte returned by the most recent successful read operation that read at least one byte. If a write has happened since the last read, if the last read returned an error, or if the read read zero bytes, UnreadByte returns an error. UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a successful ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.) Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge. WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge. WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge. WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge. WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned. *T : compress/flate.Reader *T : expvar.Var *T : fmt.Stringer *T : image/jpeg.Reader *T : io.ByteReader *T : io.ByteScanner *T : io.ByteWriter *T : io.Reader *T : io.ReaderFrom *T : io.ReadWriter *T : io.RuneReader *T : io.RuneScanner *T : io.StringWriter *T : io.Writer *T : io.WriterTo func NewWriter() *Writer
Exported Values
var BreakTimestampsForTesting bool BreakTimestampsForTesting causes the parser to randomly alter timestamps (for testing of broken cputicks).
var ErrTimeOrder error ErrTimeOrder is returned by Parse when the trace contains time stamps that do not respect actual event ordering.
const EvBatch = 1 // start of per-P batch of events [pid, timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvCount = 49 Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
var EventDescriptions [49]struct{Name string; minVersion int; Stack bool; Args []string; SArgs []string}
const EvFrequency = 2 // contains tracer timer frequency [frequency (ticks per second)] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvFutileWakeup = 36 // denotes that the previous wakeup of this goroutine was futile [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCDone = 8 // GC done [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistDone = 44 // GC mark assist done [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistStart = 43 // GC mark assist start [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCStart = 7 // GC start [timestamp, seq, stack id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSTWDone = 10 // GC mark termination done [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSTWStart = 9 // GC mark termination start [timestamp, kind] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepDone = 12 // GC sweep done [timestamp, swept, reclaimed] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepStart = 11 // GC sweep start [timestamp, stack id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlock = 20 // goroutine blocks [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockCond = 26 // goroutine blocks on Cond [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockGC = 42 // goroutine blocks on GC assist [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockNet = 27 // goroutine blocks on network [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockRecv = 23 // goroutine blocks on chan recv [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSelect = 24 // goroutine blocks on select [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSend = 22 // goroutine blocks on chan send [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSync = 25 // goroutine blocks on Mutex/RWMutex [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoCreate = 13 // goroutine creation [timestamp, new goroutine id, new stack id, stack id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoEnd = 15 // goroutine ends [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoInSyscall = 32 // denotes that goroutine is in syscall when tracing starts [timestamp, goroutine id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGomaxprocs = 4 // current value of GOMAXPROCS [timestamp, GOMAXPROCS, stack id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoPreempt = 18 // goroutine is preempted [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSched = 17 // goroutine calls Gosched [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSleep = 19 // goroutine calls Sleep [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStart = 14 // goroutine starts running [timestamp, goroutine id, seq] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLabel = 41 // goroutine starts running with label [timestamp, goroutine id, seq, label string id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLocal = 38 // goroutine starts running on the same P as the last event [timestamp, goroutine id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStop = 16 // goroutine stops (like in select{}) [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysBlock = 30 // syscall blocks [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysCall = 28 // syscall enter [timestamp, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExit = 29 // syscall exit [timestamp, goroutine id, seq, real timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExitLocal = 40 // syscall exit on the same P as the last event [timestamp, goroutine id, real timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblock = 21 // goroutine is unblocked [timestamp, goroutine id, seq, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblockLocal = 39 // goroutine is unblocked on the same P as the last event [timestamp, goroutine id, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoWaiting = 31 // denotes that goroutine is blocked when tracing starts [timestamp, goroutine id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvHeapAlloc = 33 // memstats.heap_live change [timestamp, heap_alloc] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvNextGC = 34 // memstats.next_gc change [timestamp, next_gc] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvNone = 0 // unused Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStart = 5 // start of P [timestamp, thread id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStop = 6 // stop of P [timestamp] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvStack = 3 // stack [stack id, number of PCs, array of {PC, func string ID, file string ID, line}] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvString = 37 // string dictionary entry [ID, length, string] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvTimerGoroutine = 35 // denotes timer goroutine [timer goroutine id] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserLog = 48 // trace.Log [timestamp, internal id, key string id, stack, value string] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserRegion = 47 // trace.WithRegion [timestamp, internal task id, mode(0:start, 1:end), stack, name string] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskCreate = 45 // trace.NewContext [timestamp, internal task id, internal parent id, stack, name string] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskEnd = 46 // end of task [timestamp, internal task id, stack] Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const FakeP = 1000000 Special P identifiers:
const GCP = 1000004 // depicts GC state
func GoroutineStats(events []*Event) map[uint64]*GDesc GoroutineStats generates statistics for all goroutines in the trace.
func MutatorUtilization(events []*Event, flags UtilFlags) [][]MutatorUtil MutatorUtilization returns a set of mutator utilization functions for the given trace. Each function will always end with 0 utilization. The bounds of each function are implicit in the first and last event; outside of these bounds each function is undefined. If the UtilPerProc flag is not given, this always returns a single utilization function. Otherwise, it returns one function per P.
const NetpollP = 1000002 // depicts network unblocks
func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve NewMMUCurve returns an MMU curve for the given mutator utilization function.
func NewWriter() *Writer
func Parse(r io.Reader, bin string) (ParseResult, error) Parse parses, post-processes and verifies the trace.
func Print(events []*Event) Print dumps events to stdout. For debugging.
func PrintEvent(ev *Event) PrintEvent dumps the event to stdout. For debugging.
func RelatedGoroutines(events []*Event, goid uint64) map[uint64]bool RelatedGoroutines finds a set of goroutines related to goroutine goid.
const SyscallP = 1000003 // depicts returns from syscalls
const TimerP = 1000001 // depicts timer unblocks
const UtilAssist UtilFlags = 4 UtilAssist means utilization should account for mark assists.
const UtilBackground UtilFlags = 2 UtilBackground means utilization should account for background mark workers.
const UtilPerProc UtilFlags = 16 UtilPerProc means each P should be given a separate utilization function. Otherwise, there is a single function and each P is given a fraction of the utilization.
const UtilSTW UtilFlags = 1 UtilSTW means utilization should account for STW events.
const UtilSweep UtilFlags = 8 UtilSweep means utilization should account for sweeping.