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.CallExprEvent types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvBatch event.Type = 1Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvCPUSample event.Type = 49Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvCount event.Type = 50Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvFrequency event.Type = 2Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvFutileWakeup event.Type = 36Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCDone event.Type = 8Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistDone event.Type = 44Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCMarkAssistStart event.Type = 43Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCStart event.Type = 7Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepDone event.Type = 12Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGCSweepStart event.Type = 11Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlock event.Type = 20Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockCond event.Type = 26Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockGC event.Type = 42Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockNet event.Type = 27Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockRecv event.Type = 23Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSelect event.Type = 24Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSend event.Type = 22Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoBlockSync event.Type = 25Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoCreate event.Type = 13Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoEnd event.Type = 15Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoInSyscall event.Type = 32Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoPreempt event.Type = 18Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSched event.Type = 17Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSleep event.Type = 19Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStart event.Type = 14Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLabel event.Type = 41Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStartLocal event.Type = 38Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoStop event.Type = 16Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysBlock event.Type = 30Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysCall event.Type = 28Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExit event.Type = 29Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoSysExitLocal event.Type = 40Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblock event.Type = 21Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoUnblockLocal event.Type = 39Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGoWaiting event.Type = 31Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvGomaxprocs event.Type = 4Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvHeapAlloc event.Type = 33Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvHeapGoal event.Type = 34Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvNone event.Type = 0Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStart event.Type = 5Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvProcStop event.Type = 6Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvSTWDone event.Type = 10Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvSTWStart event.Type = 9Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvStack event.Type = 3Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvString event.Type = 37Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvTimerGoroutine event.Type = 35Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserLog event.Type = 48Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserRegion event.Type = 47Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskCreate event.Type = 45Event types in the trace. Verbatim copy from src/runtime/trace.go with the "trace" prefix removed.
const EvUserTaskEnd event.Type = 46var EventDescriptions = [256]struct{...}{...}Special P identifiers:
const FakeP = *ast.BinaryExprconst GCPconst NetpollPconst NumSTWReasons = 17const ProfilePconst STWAllGoroutinesStackTrace STWReason = 6const STWAllThreadsSyscall STWReason = 8const STWCountPagesInUse STWReason = 12const STWGCMarkTermination STWReason = 1const STWGCSweepTermination STWReason = 2const STWGOMAXPROCS STWReason = 9const STWGoroutineProfile STWReason = 4const STWGoroutineProfileCleanup STWReason = 5const STWPageCachePagesLeaked STWReason = 15const STWReadMemStats STWReason = 7const STWReadMemStatsSlow STWReason = 14const STWReadMetricsSlow STWReason = 13const STWResetDebugLog STWReason = 16const STWStartTrace STWReason = 10const STWStopTrace STWReason = 11const STWUnknown STWReason = 0const STWWriteHeapDump STWReason = 3const SyscallPconst TimerPvar errMalformedVarint = *ast.CallExprconst eventsBucketSize = 524288const gDead gStatus = iotaconst gRunnableconst gRunningconst gWaitingconst garbage = *ast.BinaryExprconst noseq = *ast.UnaryExprconst seqinc = *ast.BinaryExprconst skipArgs = *ast.BinaryExprconst skipStringsconst unordered = *ast.UnaryExprtype STWReason intTimestamp 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 int64type gStatus inttype orderEventList []orderEventEvent 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() intfunc (l *Events) Less(i int, j int) boolfunc (l *orderEventList) Less(i int, j int) boolParse 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() orderEventfunc (l *Events) Pop() (*Event, bool)func (l *Events) Ptr(i int) *Eventfunc (h *orderEventList) Push(x orderEvent)func (tr *Trace) STWReason(kindID uint64) STWReasonfunc (ev *Event) String() stringfunc (l *Events) Swap(i int, j int)gcassert:inline
func (p *parser) allocateStack(size uint64) []uint64append appends v to the slice and returns a pointer to the new element.
func (l *Events) append(v Event) *EventargNum returns total number of args for the event accounting for timestamps, sequence numbers and differences between trace format versions.
func (raw *rawEvent) argNum() intcollectBatchesAndCPUSamples records the offsets of batches and parses CPU samples.
func (p *parser) collectBatchesAndCPUSamples() errorfunc (p *parser) discard(n uint64) boolgrow grows the slice by one and returns a pointer to the new element, without overwriting it.
func (l *Events) grow() *Eventfunc heapDown(h *orderEventList, i0 int, n int) boolfunc 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) errorparseEventBatches 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) errorfunc (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) errorfunc (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) errorfunc transitionReady(g uint64, curr gState, init gState) boolGenerated with Arrow