Imports #
"errors"
"bytes"
"cmp"
"encoding/binary"
"errors"
"fmt"
"internal/trace/event"
"internal/trace/version"
"io"
"math"
"slices"
"sort"
"errors"
"bytes"
"cmp"
"encoding/binary"
"errors"
"fmt"
"internal/trace/event"
"internal/trace/version"
"io"
"math"
"slices"
"sort"
ErrTimeOrder is returned by Parse when the trace contains time stamps that do not respect actual event ordering.
var ErrTimeOrder = *ast.CallExpr
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvBatch event.Type = 1
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvCPUSample event.Type = 49
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvCount event.Type = 50
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvFrequency event.Type = 2
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvFutileWakeup event.Type = 36
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCDone event.Type = 8
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistDone event.Type = 44
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistStart event.Type = 43
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCStart event.Type = 7
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepDone event.Type = 12
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepStart event.Type = 11
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlock event.Type = 20
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockCond event.Type = 26
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockGC event.Type = 42
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockNet event.Type = 27
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockRecv event.Type = 23
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSelect event.Type = 24
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSend event.Type = 22
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSync event.Type = 25
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoCreate event.Type = 13
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoEnd event.Type = 15
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoInSyscall event.Type = 32
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoPreempt event.Type = 18
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSched event.Type = 17
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSleep event.Type = 19
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStart event.Type = 14
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLabel event.Type = 41
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLocal event.Type = 38
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStop event.Type = 16
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysBlock event.Type = 30
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysCall event.Type = 28
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExit event.Type = 29
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExitLocal event.Type = 40
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblock event.Type = 21
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblockLocal event.Type = 39
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoWaiting event.Type = 31
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGomaxprocs event.Type = 4
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvHeapAlloc event.Type = 33
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvHeapGoal event.Type = 34
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvNone event.Type = 0
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStart event.Type = 5
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStop event.Type = 6
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvSTWDone event.Type = 10
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvSTWStart event.Type = 9
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvStack event.Type = 3
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvString event.Type = 37
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvTimerGoroutine event.Type = 35
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserLog event.Type = 48
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserRegion event.Type = 47
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskCreate event.Type = 45
Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskEnd event.Type = 46
var EventDescriptions = [256]struct{...}{...}
Special P identifiers:
const FakeP = *ast.BinaryExpr
const GCP
const NetpollP
const NumSTWReasons = 17
const ProfileP
const STWAllGoroutinesStackTrace STWReason = 6
const STWAllThreadsSyscall STWReason = 8
const STWCountPagesInUse STWReason = 12
const STWGCMarkTermination STWReason = 1
const STWGCSweepTermination STWReason = 2
const STWGOMAXPROCS STWReason = 9
const STWGoroutineProfile STWReason = 4
const STWGoroutineProfileCleanup STWReason = 5
const STWPageCachePagesLeaked STWReason = 15
const STWReadMemStats STWReason = 7
const STWReadMemStatsSlow STWReason = 14
const STWReadMetricsSlow STWReason = 13
const STWResetDebugLog STWReason = 16
const STWStartTrace STWReason = 10
const STWStopTrace STWReason = 11
const STWUnknown STWReason = 0
const STWWriteHeapDump STWReason = 3
const SyscallP
const TimerP
var errMalformedVarint = *ast.CallExpr
const eventsBucketSize = 524288
const gDead gStatus = iota
const gRunnable
const gRunning
const gWaiting
const garbage = *ast.BinaryExpr
const noseq = *ast.UnaryExpr
const seqinc = *ast.BinaryExpr
const skipArgs = *ast.BinaryExpr
const skipStrings
const unordered = *ast.UnaryExpr
type STWReason int
Timestamp represents a count of nanoseconds since the beginning of the trace. They can only be meaningfully compared with other timestamps from the same trace.
type Timestamp int64
type gStatus int
type orderEventList []orderEvent
Event describes one event in the trace.
type Event struct {
Ts Timestamp
G uint64
Args [4]uint64
StkID uint32
P int32
Type event.Type
}
type Events struct {
n int
buckets []*[eventsBucketSize]Event
off int
}
Frame is a frame in stack traces.
type Frame struct {
PC uint64
Fn uint64
File uint64
Line int
}
Trace is the result of Parse.
type Trace struct {
Version version.Version
Events Events
Stacks map[uint32][]uint64
PCs map[uint64]Frame
Strings map[uint64]string
InlineStrings []string
}
batchOffset records the byte offset of, and number of events in, a batch. A batch is a sequence of events emitted by a P. Events within a single batch are sorted by time.
type batchOffset struct {
offset int
numEvents int
}
type gState struct {
seq uint64
status gStatus
}
type orderEvent struct {
ev Event
proc *proc
}
type parser struct {
ver version.Version
data []byte
off int
strings map[uint64]string
inlineStrings []string
inlineStringsMapping map[string]int
batchOffsets map[int32][]batchOffset
stacks map[uint32][]uint64
stacksData []uint64
ticksPerSec int64
pcs map[uint64]Frame
cpuSamples []Event
timerGoids map[uint64]bool
args []uint64
lastTs Timestamp
lastG uint64
lastGs map[int32]uint64
lastP int32
}
type proc struct {
pid int32
events []Event
buf []Event
done bool
}
rawEvent is a helper type used during parsing.
type rawEvent struct {
typ event.Type
args []uint64
sargs []string
batchPid int32
batchOffset int
}
func (l *Events) All() (func(yield func(ev *Event) bool))
func (l *Events) Len() int
func (l *Events) Less(i int, j int) bool
func (l *orderEventList) Less(i int, j int) bool
Parse parses Go execution traces from versions 1.11–1.21. The provided reader will be read to completion and the entire trace will be materialized in memory. That is, this function does not allow incremental parsing. The reader has to be positioned just after the trace header and vers needs to be the version of the trace. This can be achieved by using version.ReadHeader.
func Parse(r io.Reader, vers version.Version) (Trace, error)
func (h *orderEventList) Pop() orderEvent
func (l *Events) Pop() (*Event, bool)
func (l *Events) Ptr(i int) *Event
func (h *orderEventList) Push(x orderEvent)
func (tr *Trace) STWReason(kindID uint64) STWReason
func (ev *Event) String() string
func (l *Events) Swap(i int, j int)
gcassert:inline
func (p *parser) allocateStack(size uint64) []uint64
append appends v to the slice and returns a pointer to the new element.
func (l *Events) append(v Event) *Event
argNum returns total number of args for the event accounting for timestamps, sequence numbers and differences between trace format versions.
func (raw *rawEvent) argNum() int
collectBatchesAndCPUSamples records the offsets of batches and parses CPU samples.
func (p *parser) collectBatchesAndCPUSamples() error
func (p *parser) discard(n uint64) bool
grow grows the slice by one and returns a pointer to the new element, without overwriting it.
func (l *Events) grow() *Event
func heapDown(h *orderEventList, i0 int, n int) bool
func heapUp(h *orderEventList, j int)
func (l *Events) index(i int) (int, int)
loadBatch loads the next batch for pid and appends its contents to events.
func (p *parser) loadBatch(pid int32, events []Event) ([]Event, error)
func newParser(r io.Reader, ver version.Version) (*parser, error)
parse parses, post-processes and verifies the trace.
func (p *parser) parse() (Trace, error)
parseEvent transforms raw events into events. It does analyze and verify per-event-type arguments.
func (p *parser) parseEvent(raw *rawEvent, ev *Event) error
parseEventBatches reads per-P event batches and merges them into a single, consistent stream. The high level idea is as follows. Events within an individual batch are in correct order, because they are emitted by a single P. So we need to produce a correct interleaving of the batches. To do this we take first unmerged event from each batch (frontier). Then choose subset that is "ready" to be merged, that is, events for which all dependencies are already merged. Then we choose event with the lowest timestamp from the subset, merge it and repeat. This approach ensures that we form a consistent stream even if timestamps are incorrect (condition observed on some machines).
func (p *parser) parseEventBatches() (Events, error)
postProcessTrace does inter-event verification and information restoration. The resulting trace is guaranteed to be consistent (for example, a P does not run two Gs at the same time, or a G is indeed blocked before an unblock event).
func (p *parser) postProcessTrace(events Events) error
func (p *parser) readByte() (byte, bool)
func (p *parser) readFull(n int) ([]byte, error)
readRawEvent reads a raw event into ev. The slices in ev are only valid until the next call to readRawEvent, even when storing to a different location.
func (p *parser) readRawEvent(flags uint, ev *rawEvent) error
func (p *parser) readStr() (s string, err error)
readVal reads unsigned base-128 value from r.
func (p *parser) readVal() (uint64, error)
func readValFrom(buf []byte) (v uint64, rem []byte, err error)
stateTransition returns goroutine state (sequence and status) when the event becomes ready for merging (init) and the goroutine state after the event (next).
func stateTransition(ev *Event) (g uint64, init gState, next gState)
func transition(gs map[uint64]gState, g uint64, init gState, next gState) error
func transitionReady(g uint64, curr gState, init gState) bool
Generated with Arrow