github.com/primecitizens/pcz/std@v0.2.1/core/trace/trace.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package trace 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/arch" 8 ) 9 10 const ( 11 // Timestamps in trace are cputicks/traceTickDiv. 12 // This makes absolute values of timestamp diffs smaller, 13 // and so they are encoded in less number of bytes. 14 // 64 on x86 is somewhat arbitrary (one tick is ~20ns on a 3GHz machine). 15 // The suggested increment frequency for PowerPC's time base register is 16 // 512 MHz according to Power ISA v2.07 section 6.2, so we use 16 on ppc64 17 // and ppc64le. 18 TimeDiv = 16 + 48*(arch.Is386|arch.IsAmd64) 19 // Maximum number of PCs in a single stack trace. 20 // Since events contain only stack id rather than whole stack trace, 21 // we can allow quite large values here. 22 StackSize = 128 23 // Identifier of a fake P that is used when we trace without a real P. 24 GlobProc = -1 25 // Maximum number of bytes to encode uint64 in base-128. 26 BytesPerNumber = 10 27 // Shift of the number of arguments in the first event byte. 28 ArgCountShift = 6 29 ) 30 31 // Event types in the trace, args are given in square brackets. 32 const ( 33 EvNone = 0 // unused 34 EvBatch = 1 // start of per-P batch of events [pid, timestamp] 35 EvFrequency = 2 // contains tracer timer frequency [frequency (ticks per second)] 36 EvStack = 3 // stack [stack id, number of PCs, array of {PC, func string ID, file string ID, line}] 37 EvGomaxprocs = 4 // current value of GOMAXPROCS [timestamp, GOMAXPROCS, stack id] 38 EvProcStart = 5 // start of P [timestamp, thread id] 39 EvProcStop = 6 // stop of P [timestamp] 40 EvGCStart = 7 // GC start [timestamp, seq, stack id] 41 EvGCDone = 8 // GC done [timestamp] 42 EvSTWStart = 9 // STW start [timestamp, kind] 43 EvSTWDone = 10 // STW done [timestamp] 44 EvGCSweepStart = 11 // GC sweep start [timestamp, stack id] 45 EvGCSweepDone = 12 // GC sweep done [timestamp, swept, reclaimed] 46 EvGoCreate = 13 // goroutine creation [timestamp, new goroutine id, new stack id, stack id] 47 EvGoStart = 14 // goroutine starts running [timestamp, goroutine id, seq] 48 EvGoEnd = 15 // goroutine ends [timestamp] 49 EvGoStop = 16 // goroutine stops (like in select{}) [timestamp, stack] 50 EvGoSched = 17 // goroutine calls Gosched [timestamp, stack] 51 EvGoPreempt = 18 // goroutine is preempted [timestamp, stack] 52 EvGoSleep = 19 // goroutine calls Sleep [timestamp, stack] 53 EvGoBlock = 20 // goroutine blocks [timestamp, stack] 54 EvGoUnblock = 21 // goroutine is unblocked [timestamp, goroutine id, seq, stack] 55 EvGoBlockSend = 22 // goroutine blocks on chan send [timestamp, stack] 56 EvGoBlockRecv = 23 // goroutine blocks on chan recv [timestamp, stack] 57 EvGoBlockSelect = 24 // goroutine blocks on select [timestamp, stack] 58 EvGoBlockSync = 25 // goroutine blocks on Mutex/RWMutex [timestamp, stack] 59 EvGoBlockCond = 26 // goroutine blocks on Cond [timestamp, stack] 60 EvGoBlockNet = 27 // goroutine blocks on network [timestamp, stack] 61 EvGoSysCall = 28 // syscall enter [timestamp, stack] 62 EvGoSysExit = 29 // syscall exit [timestamp, goroutine id, seq, real timestamp] 63 EvGoSysBlock = 30 // syscall blocks [timestamp] 64 EvGoWaiting = 31 // denotes that goroutine is blocked when tracing starts [timestamp, goroutine id] 65 EvGoInSyscall = 32 // denotes that goroutine is in syscall when tracing starts [timestamp, goroutine id] 66 EvHeapAlloc = 33 // gcController.heapLive change [timestamp, heap_alloc] 67 EvHeapGoal = 34 // gcController.heapGoal() (formerly next_gc) change [timestamp, heap goal in bytes] 68 EvTimerGoroutine = 35 // not currently used; previously denoted timer goroutine [timer goroutine id] 69 EvFutileWakeup = 36 // not currently used; denotes that the previous wakeup of this goroutine was futile [timestamp] 70 EvString = 37 // string dictionary entry [ID, length, string] 71 EvGoStartLocal = 38 // goroutine starts running on the same P as the last event [timestamp, goroutine id] 72 EvGoUnblockLocal = 39 // goroutine is unblocked on the same P as the last event [timestamp, goroutine id, stack] 73 EvGoSysExitLocal = 40 // syscall exit on the same P as the last event [timestamp, goroutine id, real timestamp] 74 EvGoStartLabel = 41 // goroutine starts running with label [timestamp, goroutine id, seq, label string id] 75 EvGoBlockGC = 42 // goroutine blocks on GC assist [timestamp, stack] 76 EvGCMarkAssistStart = 43 // GC mark assist start [timestamp, stack] 77 EvGCMarkAssistDone = 44 // GC mark assist done [timestamp] 78 EvUserTaskCreate = 45 // trace.NewTask [timestamp, internal task id, internal parent task id, name string, stack] 79 EvUserTaskEnd = 46 // end of a task [timestamp, internal task id, stack] 80 EvUserRegion = 47 // trace.WithRegion [timestamp, internal task id, mode(0:start, 1:end), name string, stack] 81 EvUserLog = 48 // trace.Log [timestamp, internal task id, key string id, stack, value string] 82 EvCPUSample = 49 // CPU profiling sample [timestamp, real timestamp, real P id (-1 when absent), goroutine id, stack] 83 EvCount = 50 84 // Byte is used but only 6 bits are available for event type. 85 // The remaining 2 bits are used to specify the number of arguments. 86 // That means, the max event type value is 63. 87 ) 88 89 // BlockReason is an enumeration of reasons a goroutine might block. 90 // This is the interface the rest of the runtime uses to tell the 91 // tracer why a goroutine blocked. The tracer then propagates this information 92 // into the trace however it sees fit. 93 // 94 // Note that BlockReasons should not be compared, since reasons that are 95 // distinct by name may *not* be distinct by value. 96 type BlockReason uint8 97 98 // For maximal efficiency, just map the trace block reason directly to a trace 99 // event. 100 const ( 101 BlockGeneric BlockReason = EvGoBlock 102 BlockForever = EvGoStop 103 BlockNet = EvGoBlockNet 104 BlockSelect = EvGoBlockSelect 105 BlockCondWait = EvGoBlockCond 106 BlockSync = EvGoBlockSync 107 BlockChanSend = EvGoBlockSend 108 BlockChanRecv = EvGoBlockRecv 109 BlockGCMarkAssist = EvGoBlockGC 110 BlockGCSweep = EvGoBlock 111 BlockSystemGoroutine = EvGoBlock 112 BlockPreempted = EvGoBlock 113 BlockDebugCall = EvGoBlock 114 BlockUntilGCEnds = EvGoBlock 115 BlockSleep = EvGoSleep 116 )