github.com/Rookout/GoSDK@v0.1.48/pkg/services/callstack/common_runtime_links_amd64.go (about) 1 //go:build amd64 && go1.15 && !go1.22 2 // +build amd64,go1.15,!go1.22 3 4 package callstack 5 6 import ( 7 "runtime" 8 9 "github.com/Rookout/GoSDK/pkg/services/go_runtime" 10 11 _ "unsafe" 12 ) 13 14 15 const ( 16 17 18 19 20 21 22 23 24 25 26 27 28 // goroutines found in the run queue, rather than CAS-looping 29 30 31 32 33 34 35 _Gidle = iota 36 37 38 39 _Grunnable 40 41 42 43 44 _Grunning 45 46 47 48 // goroutine. It is not on a run queue. It is assigned an M. 49 _Gsyscall 50 51 52 53 54 55 56 57 58 // goroutine enters _Gwaiting (e.G., it may get moved). 59 _Gwaiting 60 61 62 63 _Gmoribund_unused 64 65 66 67 68 69 70 71 _Gdead 72 73 74 _Genqueue_unused 75 76 77 78 79 _Gcopystack 80 81 82 83 84 85 86 _Gpreempted 87 88 89 90 // goroutine is not executing user code and the stack is owned 91 92 93 94 95 96 97 98 99 _Gscan = 0x1000 100 _Gscanrunnable = _Gscan + _Grunnable 101 _Gscanrunning = _Gscan + _Grunning 102 _Gscansyscall = _Gscan + _Gsyscall 103 _Gscanwaiting = _Gscan + _Gwaiting 104 _Gscanpreempted = _Gscan + _Gpreempted 105 ) 106 107 //go:linkname readgstatus runtime.readgstatus 108 func readgstatus(g go_runtime.GPtr) uint32 109 110 //go:linkname isSystemGoroutine runtime.isSystemGoroutine 111 func isSystemGoroutine(g go_runtime.GPtr, fixed bool) bool 112 113 //go:linkname saveg runtime.saveg 114 func saveg(pc, sp uintptr, g go_runtime.GPtr, r *runtime.StackRecord) 115 116 117 var ( 118 globN int 119 globOk bool 120 globCurrentG go_runtime.GPtr 121 globStbView []runtime.StackRecord 122 globCurrentStb *StackTraceBuffer 123 ) 124 125 func isOK(g1 go_runtime.GPtr) bool { 126 return g1 != globCurrentG && readgstatus(g1) != _Gdead && !isSystemGoroutine(g1, false) 127 } 128 129 func countg(g1 go_runtime.GPtr) { 130 if isOK(g1) { 131 globN++ 132 } 133 } 134 135 func saveGoroutine(g1 go_runtime.GPtr) { 136 if !isOK(g1) { 137 return 138 } 139 140 if len(globStbView) == 0 { 141 142 143 return 144 } 145 saveg(^uintptr(0), ^uintptr(0), g1, &globStbView[0]) 146 globCurrentStb.filled++ 147 globStbView = globStbView[1:] 148 }