github.com/bir3/gocompiler@v0.9.2202/src/internal/trace/v2/event/go122/event.go (about) 1 // Copyright 2023 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 package go122 6 7 import ( 8 "fmt" 9 "github.com/bir3/gocompiler/src/internal/trace/v2/event" 10 ) 11 12 const ( 13 EvNone event.Type = iota // unused 14 15 // Structural events. 16 EvEventBatch // start of per-M batch of events [generation, M ID, timestamp, batch length] 17 EvStacks // start of a section of the stack table [...EvStack] 18 EvStack // stack table entry [ID, ...{PC, func string ID, file string ID, line #}] 19 EvStrings // start of a section of the string dictionary [...EvString] 20 EvString // string dictionary entry [ID, length, string] 21 EvCPUSamples // start of a section of CPU samples [...EvCPUSample] 22 EvCPUSample // CPU profiling sample [timestamp, M ID, P ID, goroutine ID, stack ID] 23 EvFrequency // timestamp units per sec [freq] 24 25 // Procs. 26 EvProcsChange // current value of GOMAXPROCS [timestamp, GOMAXPROCS, stack ID] 27 EvProcStart // start of P [timestamp, P ID, P seq] 28 EvProcStop // stop of P [timestamp] 29 EvProcSteal // P was stolen [timestamp, P ID, P seq, M ID] 30 EvProcStatus // P status at the start of a generation [timestamp, P ID, status] 31 32 // Goroutines. 33 EvGoCreate // goroutine creation [timestamp, new goroutine ID, new stack ID, stack ID] 34 EvGoCreateSyscall // goroutine appears in syscall (cgo callback) [timestamp, new goroutine ID] 35 EvGoStart // goroutine starts running [timestamp, goroutine ID, goroutine seq] 36 EvGoDestroy // goroutine ends [timestamp] 37 EvGoDestroySyscall // goroutine ends in syscall (cgo callback) [timestamp] 38 EvGoStop // goroutine yields its time, but is runnable [timestamp, reason, stack ID] 39 EvGoBlock // goroutine blocks [timestamp, reason, stack ID] 40 EvGoUnblock // goroutine is unblocked [timestamp, goroutine ID, goroutine seq, stack ID] 41 EvGoSyscallBegin // syscall enter [timestamp, P seq, stack ID] 42 EvGoSyscallEnd // syscall exit [timestamp] 43 EvGoSyscallEndBlocked // syscall exit and it blocked at some point [timestamp] 44 EvGoStatus // goroutine status at the start of a generation [timestamp, goroutine ID, status] 45 46 // STW. 47 EvSTWBegin // STW start [timestamp, kind] 48 EvSTWEnd // STW done [timestamp] 49 50 // GC events. 51 EvGCActive // GC active [timestamp, seq] 52 EvGCBegin // GC start [timestamp, seq, stack ID] 53 EvGCEnd // GC done [timestamp, seq] 54 EvGCSweepActive // GC sweep active [timestamp, P ID] 55 EvGCSweepBegin // GC sweep start [timestamp, stack ID] 56 EvGCSweepEnd // GC sweep done [timestamp, swept bytes, reclaimed bytes] 57 EvGCMarkAssistActive // GC mark assist active [timestamp, goroutine ID] 58 EvGCMarkAssistBegin // GC mark assist start [timestamp, stack ID] 59 EvGCMarkAssistEnd // GC mark assist done [timestamp] 60 EvHeapAlloc // gcController.heapLive change [timestamp, heap alloc in bytes] 61 EvHeapGoal // gcController.heapGoal() change [timestamp, heap goal in bytes] 62 63 // Annotations. 64 EvGoLabel // apply string label to current running goroutine [timestamp, label string ID] 65 EvUserTaskBegin // trace.NewTask [timestamp, internal task ID, internal parent task ID, name string ID, stack ID] 66 EvUserTaskEnd // end of a task [timestamp, internal task ID, stack ID] 67 EvUserRegionBegin // trace.{Start,With}Region [timestamp, internal task ID, name string ID, stack ID] 68 EvUserRegionEnd // trace.{End,With}Region [timestamp, internal task ID, name string ID, stack ID] 69 EvUserLog // trace.Log [timestamp, internal task ID, key string ID, stack, value string ID] 70 ) 71 72 // EventString returns the name of a Go 1.22 event. 73 func EventString(typ event.Type) string { 74 if int(typ) < len(specs) { 75 return specs[typ].Name 76 } 77 return fmt.Sprintf("Invalid(%d)", typ) 78 } 79 80 func Specs() []event.Spec { 81 return specs[:] 82 } 83 84 var specs = [...]event.Spec{ 85 // "Structural" Events. 86 EvEventBatch: event.Spec{ 87 Name: "EventBatch", 88 Args: []string{"gen", "m", "time", "size"}, 89 }, 90 EvStacks: event.Spec{ 91 Name: "Stacks", 92 }, 93 EvStack: event.Spec{ 94 Name: "Stack", 95 Args: []string{"id", "nframes"}, 96 IsStack: true, 97 }, 98 EvStrings: event.Spec{ 99 Name: "Strings", 100 }, 101 EvString: event.Spec{ 102 Name: "String", 103 Args: []string{"id"}, 104 HasData: true, 105 }, 106 EvCPUSamples: event.Spec{ 107 Name: "CPUSamples", 108 }, 109 EvCPUSample: event.Spec{ 110 Name: "CPUSample", 111 Args: []string{"time", "p", "g", "m", "stack"}, 112 // N.B. There's clearly a timestamp here, but these Events 113 // are special in that they don't appear in the regular 114 // M streams. 115 }, 116 EvFrequency: event.Spec{ 117 Name: "Frequency", 118 Args: []string{"freq"}, 119 }, 120 121 // "Timed" Events. 122 EvProcsChange: event.Spec{ 123 Name: "ProcsChange", 124 Args: []string{"dt", "procs_value", "stack"}, 125 IsTimedEvent: true, 126 StackIDs: []int{2}, 127 }, 128 EvProcStart: event.Spec{ 129 Name: "ProcStart", 130 Args: []string{"dt", "p", "p_seq"}, 131 IsTimedEvent: true, 132 }, 133 EvProcStop: event.Spec{ 134 Name: "ProcStop", 135 Args: []string{"dt"}, 136 IsTimedEvent: true, 137 }, 138 EvProcSteal: event.Spec{ 139 Name: "ProcSteal", 140 Args: []string{"dt", "p", "p_seq", "m"}, 141 IsTimedEvent: true, 142 }, 143 EvProcStatus: event.Spec{ 144 Name: "ProcStatus", 145 Args: []string{"dt", "p", "pstatus"}, 146 IsTimedEvent: true, 147 }, 148 EvGoCreate: event.Spec{ 149 Name: "GoCreate", 150 Args: []string{"dt", "new_g", "new_stack", "stack"}, 151 IsTimedEvent: true, 152 StackIDs: []int{3, 2}, 153 }, 154 EvGoCreateSyscall: event.Spec{ 155 Name: "GoCreateSyscall", 156 Args: []string{"dt", "new_g"}, 157 IsTimedEvent: true, 158 }, 159 EvGoStart: event.Spec{ 160 Name: "GoStart", 161 Args: []string{"dt", "g", "g_seq"}, 162 IsTimedEvent: true, 163 }, 164 EvGoDestroy: event.Spec{ 165 Name: "GoDestroy", 166 Args: []string{"dt"}, 167 IsTimedEvent: true, 168 }, 169 EvGoDestroySyscall: event.Spec{ 170 Name: "GoDestroySyscall", 171 Args: []string{"dt"}, 172 IsTimedEvent: true, 173 }, 174 EvGoStop: event.Spec{ 175 Name: "GoStop", 176 Args: []string{"dt", "reason_string", "stack"}, 177 IsTimedEvent: true, 178 StackIDs: []int{2}, 179 StringIDs: []int{1}, 180 }, 181 EvGoBlock: event.Spec{ 182 Name: "GoBlock", 183 Args: []string{"dt", "reason_string", "stack"}, 184 IsTimedEvent: true, 185 StackIDs: []int{2}, 186 StringIDs: []int{1}, 187 }, 188 EvGoUnblock: event.Spec{ 189 Name: "GoUnblock", 190 Args: []string{"dt", "g", "g_seq", "stack"}, 191 IsTimedEvent: true, 192 StackIDs: []int{3}, 193 }, 194 EvGoSyscallBegin: event.Spec{ 195 Name: "GoSyscallBegin", 196 Args: []string{"dt", "p_seq", "stack"}, 197 IsTimedEvent: true, 198 StackIDs: []int{2}, 199 }, 200 EvGoSyscallEnd: event.Spec{ 201 Name: "GoSyscallEnd", 202 Args: []string{"dt"}, 203 StartEv: EvGoSyscallBegin, 204 IsTimedEvent: true, 205 }, 206 EvGoSyscallEndBlocked: event.Spec{ 207 Name: "GoSyscallEndBlocked", 208 Args: []string{"dt"}, 209 StartEv: EvGoSyscallBegin, 210 IsTimedEvent: true, 211 }, 212 EvGoStatus: event.Spec{ 213 Name: "GoStatus", 214 Args: []string{"dt", "g", "m", "gstatus"}, 215 IsTimedEvent: true, 216 }, 217 EvSTWBegin: event.Spec{ 218 Name: "STWBegin", 219 Args: []string{"dt", "kind_string", "stack"}, 220 IsTimedEvent: true, 221 StackIDs: []int{2}, 222 StringIDs: []int{1}, 223 }, 224 EvSTWEnd: event.Spec{ 225 Name: "STWEnd", 226 Args: []string{"dt"}, 227 StartEv: EvSTWBegin, 228 IsTimedEvent: true, 229 }, 230 EvGCActive: event.Spec{ 231 Name: "GCActive", 232 Args: []string{"dt", "gc_seq"}, 233 IsTimedEvent: true, 234 StartEv: EvGCBegin, 235 }, 236 EvGCBegin: event.Spec{ 237 Name: "GCBegin", 238 Args: []string{"dt", "gc_seq", "stack"}, 239 IsTimedEvent: true, 240 StackIDs: []int{2}, 241 }, 242 EvGCEnd: event.Spec{ 243 Name: "GCEnd", 244 Args: []string{"dt", "gc_seq"}, 245 StartEv: EvGCBegin, 246 IsTimedEvent: true, 247 }, 248 EvGCSweepActive: event.Spec{ 249 Name: "GCSweepActive", 250 Args: []string{"dt", "p"}, 251 StartEv: EvGCSweepBegin, 252 IsTimedEvent: true, 253 }, 254 EvGCSweepBegin: event.Spec{ 255 Name: "GCSweepBegin", 256 Args: []string{"dt", "stack"}, 257 IsTimedEvent: true, 258 StackIDs: []int{1}, 259 }, 260 EvGCSweepEnd: event.Spec{ 261 Name: "GCSweepEnd", 262 Args: []string{"dt", "swept_value", "reclaimed_value"}, 263 StartEv: EvGCSweepBegin, 264 IsTimedEvent: true, 265 }, 266 EvGCMarkAssistActive: event.Spec{ 267 Name: "GCMarkAssistActive", 268 Args: []string{"dt", "g"}, 269 StartEv: EvGCMarkAssistBegin, 270 IsTimedEvent: true, 271 }, 272 EvGCMarkAssistBegin: event.Spec{ 273 Name: "GCMarkAssistBegin", 274 Args: []string{"dt", "stack"}, 275 IsTimedEvent: true, 276 StackIDs: []int{1}, 277 }, 278 EvGCMarkAssistEnd: event.Spec{ 279 Name: "GCMarkAssistEnd", 280 Args: []string{"dt"}, 281 StartEv: EvGCMarkAssistBegin, 282 IsTimedEvent: true, 283 }, 284 EvHeapAlloc: event.Spec{ 285 Name: "HeapAlloc", 286 Args: []string{"dt", "heapalloc_value"}, 287 IsTimedEvent: true, 288 }, 289 EvHeapGoal: event.Spec{ 290 Name: "HeapGoal", 291 Args: []string{"dt", "heapgoal_value"}, 292 IsTimedEvent: true, 293 }, 294 EvGoLabel: event.Spec{ 295 Name: "GoLabel", 296 Args: []string{"dt", "label_string"}, 297 IsTimedEvent: true, 298 StringIDs: []int{1}, 299 }, 300 EvUserTaskBegin: event.Spec{ 301 Name: "UserTaskBegin", 302 Args: []string{"dt", "task", "parent_task", "name_string", "stack"}, 303 IsTimedEvent: true, 304 StackIDs: []int{4}, 305 StringIDs: []int{3}, 306 }, 307 EvUserTaskEnd: event.Spec{ 308 Name: "UserTaskEnd", 309 Args: []string{"dt", "task", "stack"}, 310 IsTimedEvent: true, 311 StackIDs: []int{2}, 312 }, 313 EvUserRegionBegin: event.Spec{ 314 Name: "UserRegionBegin", 315 Args: []string{"dt", "task", "name_string", "stack"}, 316 IsTimedEvent: true, 317 StackIDs: []int{3}, 318 StringIDs: []int{2}, 319 }, 320 EvUserRegionEnd: event.Spec{ 321 Name: "UserRegionEnd", 322 Args: []string{"dt", "task", "name_string", "stack"}, 323 StartEv: EvUserRegionBegin, 324 IsTimedEvent: true, 325 StackIDs: []int{3}, 326 StringIDs: []int{2}, 327 }, 328 EvUserLog: event.Spec{ 329 Name: "UserLog", 330 Args: []string{"dt", "task", "key_string", "value_string", "stack"}, 331 IsTimedEvent: true, 332 StackIDs: []int{4}, 333 StringIDs: []int{2, 3}, 334 }, 335 } 336 337 type GoStatus uint8 338 339 const ( 340 GoBad GoStatus = iota 341 GoRunnable 342 GoRunning 343 GoSyscall 344 GoWaiting 345 ) 346 347 func (s GoStatus) String() string { 348 switch s { 349 case GoRunnable: 350 return "Runnable" 351 case GoRunning: 352 return "Running" 353 case GoSyscall: 354 return "Syscall" 355 case GoWaiting: 356 return "Waiting" 357 } 358 return "Bad" 359 } 360 361 type ProcStatus uint8 362 363 const ( 364 ProcBad ProcStatus = iota 365 ProcRunning 366 ProcIdle 367 ProcSyscall 368 ProcSyscallAbandoned 369 ) 370 371 func (s ProcStatus) String() string { 372 switch s { 373 case ProcRunning: 374 return "Running" 375 case ProcIdle: 376 return "Idle" 377 case ProcSyscall: 378 return "Syscall" 379 } 380 return "Bad" 381 } 382 383 const ( 384 // Various format-specific constants. 385 MaxBatchSize = 64 << 10 386 MaxFramesPerStack = 128 387 MaxStringSize = 1 << 10 388 )