github.com/sitano/gsysint@v0.0.0-20190607084937-69a4f3233e4e/trace/trace.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Go execution tracer. 6 // The tracer captures a wide range of execution events like goroutine 7 // creation/blocking/unblocking, syscall enter/exit/block, GC-related events, 8 // changes of heap size, processor start/stop, etc and writes them to a buffer 9 // in a compact form. A precise nanosecond-precision timestamp and a stack 10 // trace is captured for most events. 11 // See https://golang.org/s/go15trace for more info. 12 13 package trace 14 15 import ( 16 "github.com/sitano/gsysint/sys" 17 ) 18 19 // Event types in the trace, args are given in square brackets. 20 const ( 21 TraceEvNone = 0 // unused 22 TraceEvBatch = 1 // start of per-P batch of events [pid, timestamp] 23 TraceEvFrequency = 2 // contains tracer timer frequency [frequency (ticks per second)] 24 TraceEvStack = 3 // stack [stack id, number of PCs, array of {PC, func string ID, file string ID, line}] 25 TraceEvGomaxprocs = 4 // current value of GOMAXPROCS [timestamp, GOMAXPROCS, stack id] 26 TraceEvProcStart = 5 // start of P [timestamp, thread id] 27 TraceEvProcStop = 6 // stop of P [timestamp] 28 TraceEvGCStart = 7 // GC start [timestamp, seq, stack id] 29 TraceEvGCDone = 8 // GC done [timestamp] 30 TraceEvGCSTWStart = 9 // GC STW start [timestamp, kind] 31 TraceEvGCSTWDone = 10 // GC STW done [timestamp] 32 TraceEvGCSweepStart = 11 // GC sweep start [timestamp, stack id] 33 TraceEvGCSweepDone = 12 // GC sweep done [timestamp, swept, reclaimed] 34 TraceEvGoCreate = 13 // goroutine creation [timestamp, new goroutine id, new stack id, stack id] 35 TraceEvGoStart = 14 // goroutine starts running [timestamp, goroutine id, seq] 36 TraceEvGoEnd = 15 // goroutine ends [timestamp] 37 TraceEvGoStop = 16 // goroutine stops (like in select{}) [timestamp, stack] 38 TraceEvGoSched = 17 // goroutine calls Gosched [timestamp, stack] 39 TraceEvGoPreempt = 18 // goroutine is preempted [timestamp, stack] 40 TraceEvGoSleep = 19 // goroutine calls Sleep [timestamp, stack] 41 TraceEvGoBlock = 20 // goroutine blocks [timestamp, stack] 42 TraceEvGoUnblock = 21 // goroutine is unblocked [timestamp, goroutine id, seq, stack] 43 TraceEvGoBlockSend = 22 // goroutine blocks on chan send [timestamp, stack] 44 TraceEvGoBlockRecv = 23 // goroutine blocks on chan recv [timestamp, stack] 45 TraceEvGoBlockSelect = 24 // goroutine blocks on select [timestamp, stack] 46 TraceEvGoBlockSync = 25 // goroutine blocks on Mutex/RWMutex [timestamp, stack] 47 TraceEvGoBlockCond = 26 // goroutine blocks on Cond [timestamp, stack] 48 TraceEvGoBlockNet = 27 // goroutine blocks on network [timestamp, stack] 49 TraceEvGoSysCall = 28 // syscall enter [timestamp, stack] 50 TraceEvGoSysExit = 29 // syscall exit [timestamp, goroutine id, seq, real timestamp] 51 TraceEvGoSysBlock = 30 // syscall blocks [timestamp] 52 TraceEvGoWaiting = 31 // denotes that goroutine is blocked when tracing starts [timestamp, goroutine id] 53 TraceEvGoInSyscall = 32 // denotes that goroutine is in syscall when tracing starts [timestamp, goroutine id] 54 TraceEvHeapAlloc = 33 // memstats.heap_live change [timestamp, heap_alloc] 55 TraceEvNextGC = 34 // memstats.next_gc change [timestamp, next_gc] 56 TraceEvTimerGoroutine = 35 // denotes timer goroutine [timer goroutine id] 57 TraceEvFutileWakeup = 36 // denotes that the previous wakeup of this goroutine was futile [timestamp] 58 TraceEvString = 37 // string dictionary entry [ID, length, string] 59 TraceEvGoStartLocal = 38 // goroutine starts running on the same P as the last event [timestamp, goroutine id] 60 TraceEvGoUnblockLocal = 39 // goroutine is unblocked on the same P as the last event [timestamp, goroutine id, stack] 61 TraceEvGoSysExitLocal = 40 // syscall exit on the same P as the last event [timestamp, goroutine id, real timestamp] 62 TraceEvGoStartLabel = 41 // goroutine starts running with label [timestamp, goroutine id, seq, label string id] 63 TraceEvGoBlockGC = 42 // goroutine blocks on GC assist [timestamp, stack] 64 TraceEvGCMarkAssistStart = 43 // GC mark assist start [timestamp, stack] 65 TraceEvGCMarkAssistDone = 44 // GC mark assist done [timestamp] 66 TraceEvUserTaskCreate = 45 // trace.NewContext [timestamp, internal task id, internal parent task id, stack, name string] 67 TraceEvUserTaskEnd = 46 // end of a task [timestamp, internal task id, stack] 68 TraceEvUserRegion = 47 // trace.WithRegion [timestamp, internal task id, mode(0:start, 1:end), stack, name string] 69 TraceEvUserLog = 48 // trace.Log [timestamp, internal task id, key string id, stack, value string] 70 TraceEvCount = 49 71 // Byte is used but only 6 bits are available for event type. 72 // The remaining 2 bits are used to specify the number of arguments. 73 // That means, the max event type value is 63. 74 ) 75 76 const ( 77 // Timestamps in trace are cputicks/traceTickDiv. 78 // This makes absolute values of timestamp diffs smaller, 79 // and so they are encoded in less number of bytes. 80 // 64 on x86 is somewhat arbitrary (one tick is ~20ns on a 3GHz machine). 81 // The suggested increment frequency for PowerPC's time base register is 82 // 512 MHz according to Power ISA v2.07 section 6.2, so we use 16 on ppc64 83 // and ppc64le. 84 // Tracing won't work reliably for architectures where cputicks is emulated 85 // by nanotime, so the value doesn't matter for those architectures. 86 TraceTickDiv = 16 + 48*(sys.Goarch386|sys.GoarchAmd64|sys.GoarchAmd64p32) 87 // Maximum number of PCs in a single stack trace. 88 // Since events contain only stack id rather than whole stack trace, 89 // we can allow quite large values here. 90 TraceStackSize = 128 91 // Identifier of a fake P that is used when we trace without a real P. 92 TraceGlobProc = -1 93 // Maximum number of bytes to encode uint64 in base-128. 94 TraceBytesPerNumber = 10 95 // Shift of the number of arguments in the first event byte. 96 TraceArgCountShift = 6 97 // Flag passed to traceGoPark to denote that the previous wakeup of this 98 // goroutine was futile. For example, a goroutine was unblocked on a mutex, 99 // but another goroutine got ahead and acquired the mutex before the first 100 // goroutine is scheduled, so the first goroutine has to block again. 101 // Such wakeups happen on buffered channels and sync.Mutex, 102 // but are generally not interesting for end user. 103 TraceFutileWakeup byte = 128 104 )