oldtrace

Imports

Imports #

"errors"
"bytes"
"cmp"
"encoding/binary"
"errors"
"fmt"
"internal/trace/event"
"internal/trace/version"
"io"
"math"
"slices"
"sort"

Constants & Variables

ErrTimeOrder var #

ErrTimeOrder is returned by Parse when the trace contains time stamps that do not respect actual event ordering.

var ErrTimeOrder = *ast.CallExpr

EvBatch const #

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

const EvBatch event.Type = 1

EvCPUSample const #

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

const EvCPUSample event.Type = 49

EvCount const #

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

const EvCount event.Type = 50

EvFrequency const #

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

const EvFrequency event.Type = 2

EvFutileWakeup const #

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

const EvFutileWakeup event.Type = 36

EvGCDone const #

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

const EvGCDone event.Type = 8

EvGCMarkAssistDone const #

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

const EvGCMarkAssistDone event.Type = 44

EvGCMarkAssistStart const #

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

const EvGCMarkAssistStart event.Type = 43

EvGCStart const #

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

const EvGCStart event.Type = 7

EvGCSweepDone const #

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

const EvGCSweepDone event.Type = 12

EvGCSweepStart const #

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

const EvGCSweepStart event.Type = 11

EvGoBlock const #

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

const EvGoBlock event.Type = 20

EvGoBlockCond const #

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

const EvGoBlockCond event.Type = 26

EvGoBlockGC const #

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

const EvGoBlockGC event.Type = 42

EvGoBlockNet const #

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

const EvGoBlockNet event.Type = 27

EvGoBlockRecv const #

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

const EvGoBlockRecv event.Type = 23

EvGoBlockSelect const #

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

const EvGoBlockSelect event.Type = 24

EvGoBlockSend const #

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

const EvGoBlockSend event.Type = 22

EvGoBlockSync const #

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

const EvGoBlockSync event.Type = 25

EvGoCreate const #

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

const EvGoCreate event.Type = 13

EvGoEnd const #

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

const EvGoEnd event.Type = 15

EvGoInSyscall const #

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

const EvGoInSyscall event.Type = 32

EvGoPreempt const #

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

const EvGoPreempt event.Type = 18

EvGoSched const #

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

const EvGoSched event.Type = 17

EvGoSleep const #

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

const EvGoSleep event.Type = 19

EvGoStart const #

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

const EvGoStart event.Type = 14

EvGoStartLabel const #

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

const EvGoStartLabel event.Type = 41

EvGoStartLocal const #

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

const EvGoStartLocal event.Type = 38

EvGoStop const #

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

const EvGoStop event.Type = 16

EvGoSysBlock const #

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

const EvGoSysBlock event.Type = 30

EvGoSysCall const #

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

const EvGoSysCall event.Type = 28

EvGoSysExit const #

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

const EvGoSysExit event.Type = 29

EvGoSysExitLocal const #

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

const EvGoSysExitLocal event.Type = 40

EvGoUnblock const #

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

const EvGoUnblock event.Type = 21

EvGoUnblockLocal const #

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

const EvGoUnblockLocal event.Type = 39

EvGoWaiting const #

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

const EvGoWaiting event.Type = 31

EvGomaxprocs const #

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

const EvGomaxprocs event.Type = 4

EvHeapAlloc const #

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

const EvHeapAlloc event.Type = 33

EvHeapGoal const #

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

const EvHeapGoal event.Type = 34

EvNone const #

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

const EvNone event.Type = 0

EvProcStart const #

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

const EvProcStart event.Type = 5

EvProcStop const #

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

const EvProcStop event.Type = 6

EvSTWDone const #

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

const EvSTWDone event.Type = 10

EvSTWStart const #

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

const EvSTWStart event.Type = 9

EvStack const #

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

const EvStack event.Type = 3

EvString const #

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

const EvString event.Type = 37

EvTimerGoroutine const #

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

const EvTimerGoroutine event.Type = 35

EvUserLog const #

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

const EvUserLog event.Type = 48

EvUserRegion const #

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

const EvUserRegion event.Type = 47

EvUserTaskCreate const #

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

const EvUserTaskCreate event.Type = 45

EvUserTaskEnd const #

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

const EvUserTaskEnd event.Type = 46

EventDescriptions var #

var EventDescriptions = [256]struct{...}{...}

FakeP const #

Special P identifiers:

const FakeP = *ast.BinaryExpr

GCP const #

const GCP

NetpollP const #

const NetpollP

NumSTWReasons const #

const NumSTWReasons = 17

ProfileP const #

const ProfileP

STWAllGoroutinesStackTrace const #

const STWAllGoroutinesStackTrace STWReason = 6

STWAllThreadsSyscall const #

const STWAllThreadsSyscall STWReason = 8

STWCountPagesInUse const #

const STWCountPagesInUse STWReason = 12

STWGCMarkTermination const #

const STWGCMarkTermination STWReason = 1

STWGCSweepTermination const #

const STWGCSweepTermination STWReason = 2

STWGOMAXPROCS const #

const STWGOMAXPROCS STWReason = 9

STWGoroutineProfile const #

const STWGoroutineProfile STWReason = 4

STWGoroutineProfileCleanup const #

const STWGoroutineProfileCleanup STWReason = 5

STWPageCachePagesLeaked const #

const STWPageCachePagesLeaked STWReason = 15

STWReadMemStats const #

const STWReadMemStats STWReason = 7

STWReadMemStatsSlow const #

const STWReadMemStatsSlow STWReason = 14

STWReadMetricsSlow const #

const STWReadMetricsSlow STWReason = 13

STWResetDebugLog const #

const STWResetDebugLog STWReason = 16

STWStartTrace const #

const STWStartTrace STWReason = 10

STWStopTrace const #

const STWStopTrace STWReason = 11

STWUnknown const #

const STWUnknown STWReason = 0

STWWriteHeapDump const #

const STWWriteHeapDump STWReason = 3

SyscallP const #

const SyscallP

TimerP const #

const TimerP

errMalformedVarint var #

var errMalformedVarint = *ast.CallExpr

eventsBucketSize const #

const eventsBucketSize = 524288

gDead const #

const gDead gStatus = iota

gRunnable const #

const gRunnable

gRunning const #

const gRunning

gWaiting const #

const gWaiting

garbage const #

const garbage = *ast.BinaryExpr

noseq const #

const noseq = *ast.UnaryExpr

seqinc const #

const seqinc = *ast.BinaryExpr

skipArgs const #

const skipArgs = *ast.BinaryExpr

skipStrings const #

const skipStrings

unordered const #

const unordered = *ast.UnaryExpr

Type Aliases

STWReason type #

type STWReason int

Timestamp type #

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

gStatus type #

type gStatus int

orderEventList type #

type orderEventList []orderEvent

Structs

Event struct #

Event describes one event in the trace.

type Event struct {
Ts Timestamp
G uint64
Args [4]uint64
StkID uint32
P int32
Type event.Type
}

Events struct #

type Events struct {
n int
buckets []*[eventsBucketSize]Event
off int
}

Frame struct #

Frame is a frame in stack traces.

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

Trace struct #

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 struct #

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
}

gState struct #

type gState struct {
seq uint64
status gStatus
}

orderEvent struct #

type orderEvent struct {
ev Event
proc *proc
}

parser struct #

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
}

proc struct #

type proc struct {
pid int32
events []Event
buf []Event
done bool
}

rawEvent struct #

rawEvent is a helper type used during parsing.

type rawEvent struct {
typ event.Type
args []uint64
sargs []string
batchPid int32
batchOffset int
}

Functions

All method #

func (l *Events) All() (func(yield func(ev *Event) bool))

Len method #

func (l *Events) Len() int

Less method #

func (l *Events) Less(i int, j int) bool

Less method #

func (l *orderEventList) Less(i int, j int) bool

Parse function #

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)

Pop method #

func (h *orderEventList) Pop() orderEvent

Pop method #

func (l *Events) Pop() (*Event, bool)

Ptr method #

func (l *Events) Ptr(i int) *Event

Push method #

func (h *orderEventList) Push(x orderEvent)

STWReason method #

func (tr *Trace) STWReason(kindID uint64) STWReason

String method #

func (ev *Event) String() string

Swap method #

func (l *Events) Swap(i int, j int)

allocateStack method #

gcassert:inline

func (p *parser) allocateStack(size uint64) []uint64

append method #

append appends v to the slice and returns a pointer to the new element.

func (l *Events) append(v Event) *Event

argNum method #

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 method #

collectBatchesAndCPUSamples records the offsets of batches and parses CPU samples.

func (p *parser) collectBatchesAndCPUSamples() error

discard method #

func (p *parser) discard(n uint64) bool

grow method #

grow grows the slice by one and returns a pointer to the new element, without overwriting it.

func (l *Events) grow() *Event

heapDown function #

func heapDown(h *orderEventList, i0 int, n int) bool

heapUp function #

func heapUp(h *orderEventList, j int)

index method #

func (l *Events) index(i int) (int, int)

loadBatch method #

loadBatch loads the next batch for pid and appends its contents to events.

func (p *parser) loadBatch(pid int32, events []Event) ([]Event, error)

newParser function #

func newParser(r io.Reader, ver version.Version) (*parser, error)

parse method #

parse parses, post-processes and verifies the trace.

func (p *parser) parse() (Trace, error)

parseEvent method #

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 method #

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 method #

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

readByte method #

func (p *parser) readByte() (byte, bool)

readFull method #

func (p *parser) readFull(n int) ([]byte, error)

readRawEvent method #

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

readStr method #

func (p *parser) readStr() (s string, err error)

readVal method #

readVal reads unsigned base-128 value from r.

func (p *parser) readVal() (uint64, error)

readValFrom function #

func readValFrom(buf []byte) (v uint64, rem []byte, err error)

stateTransition function #

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)

transition function #

func transition(gs map[uint64]gState, g uint64, init gState, next gState) error

transitionReady function #

func transitionReady(g uint64, curr gState, init gState) bool

Generated with Arrow