github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/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  	"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, thread 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, value string ID, stack]
    70  
    71  	// Coroutines. Added in Go 1.23.
    72  	EvGoSwitch        // goroutine switch (coroswitch) [timestamp, goroutine ID, goroutine seq]
    73  	EvGoSwitchDestroy // goroutine switch and destroy [timestamp, goroutine ID, goroutine seq]
    74  	EvGoCreateBlocked // goroutine creation (starts blocked) [timestamp, new goroutine ID, new stack ID, stack ID]
    75  )
    76  
    77  // EventString returns the name of a Go 1.22 event.
    78  func EventString(typ event.Type) string {
    79  	if int(typ) < len(specs) {
    80  		return specs[typ].Name
    81  	}
    82  	return fmt.Sprintf("Invalid(%d)", typ)
    83  }
    84  
    85  func Specs() []event.Spec {
    86  	return specs[:]
    87  }
    88  
    89  var specs = [...]event.Spec{
    90  	// "Structural" Events.
    91  	EvEventBatch: event.Spec{
    92  		Name: "EventBatch",
    93  		Args: []string{"gen", "m", "time", "size"},
    94  	},
    95  	EvStacks: event.Spec{
    96  		Name: "Stacks",
    97  	},
    98  	EvStack: event.Spec{
    99  		Name:    "Stack",
   100  		Args:    []string{"id", "nframes"},
   101  		IsStack: true,
   102  	},
   103  	EvStrings: event.Spec{
   104  		Name: "Strings",
   105  	},
   106  	EvString: event.Spec{
   107  		Name:    "String",
   108  		Args:    []string{"id"},
   109  		HasData: true,
   110  	},
   111  	EvCPUSamples: event.Spec{
   112  		Name: "CPUSamples",
   113  	},
   114  	EvCPUSample: event.Spec{
   115  		Name: "CPUSample",
   116  		Args: []string{"time", "m", "p", "g", "stack"},
   117  		// N.B. There's clearly a timestamp here, but these Events
   118  		// are special in that they don't appear in the regular
   119  		// M streams.
   120  	},
   121  	EvFrequency: event.Spec{
   122  		Name: "Frequency",
   123  		Args: []string{"freq"},
   124  	},
   125  
   126  	// "Timed" Events.
   127  	EvProcsChange: event.Spec{
   128  		Name:         "ProcsChange",
   129  		Args:         []string{"dt", "procs_value", "stack"},
   130  		IsTimedEvent: true,
   131  		StackIDs:     []int{2},
   132  	},
   133  	EvProcStart: event.Spec{
   134  		Name:         "ProcStart",
   135  		Args:         []string{"dt", "p", "p_seq"},
   136  		IsTimedEvent: true,
   137  	},
   138  	EvProcStop: event.Spec{
   139  		Name:         "ProcStop",
   140  		Args:         []string{"dt"},
   141  		IsTimedEvent: true,
   142  	},
   143  	EvProcSteal: event.Spec{
   144  		Name:         "ProcSteal",
   145  		Args:         []string{"dt", "p", "p_seq", "m"},
   146  		IsTimedEvent: true,
   147  	},
   148  	EvProcStatus: event.Spec{
   149  		Name:         "ProcStatus",
   150  		Args:         []string{"dt", "p", "pstatus"},
   151  		IsTimedEvent: true,
   152  	},
   153  	EvGoCreate: event.Spec{
   154  		Name:         "GoCreate",
   155  		Args:         []string{"dt", "new_g", "new_stack", "stack"},
   156  		IsTimedEvent: true,
   157  		StackIDs:     []int{3, 2},
   158  	},
   159  	EvGoCreateSyscall: event.Spec{
   160  		Name:         "GoCreateSyscall",
   161  		Args:         []string{"dt", "new_g"},
   162  		IsTimedEvent: true,
   163  	},
   164  	EvGoStart: event.Spec{
   165  		Name:         "GoStart",
   166  		Args:         []string{"dt", "g", "g_seq"},
   167  		IsTimedEvent: true,
   168  	},
   169  	EvGoDestroy: event.Spec{
   170  		Name:         "GoDestroy",
   171  		Args:         []string{"dt"},
   172  		IsTimedEvent: true,
   173  	},
   174  	EvGoDestroySyscall: event.Spec{
   175  		Name:         "GoDestroySyscall",
   176  		Args:         []string{"dt"},
   177  		IsTimedEvent: true,
   178  	},
   179  	EvGoStop: event.Spec{
   180  		Name:         "GoStop",
   181  		Args:         []string{"dt", "reason_string", "stack"},
   182  		IsTimedEvent: true,
   183  		StackIDs:     []int{2},
   184  		StringIDs:    []int{1},
   185  	},
   186  	EvGoBlock: event.Spec{
   187  		Name:         "GoBlock",
   188  		Args:         []string{"dt", "reason_string", "stack"},
   189  		IsTimedEvent: true,
   190  		StackIDs:     []int{2},
   191  		StringIDs:    []int{1},
   192  	},
   193  	EvGoUnblock: event.Spec{
   194  		Name:         "GoUnblock",
   195  		Args:         []string{"dt", "g", "g_seq", "stack"},
   196  		IsTimedEvent: true,
   197  		StackIDs:     []int{3},
   198  	},
   199  	EvGoSyscallBegin: event.Spec{
   200  		Name:         "GoSyscallBegin",
   201  		Args:         []string{"dt", "p_seq", "stack"},
   202  		IsTimedEvent: true,
   203  		StackIDs:     []int{2},
   204  	},
   205  	EvGoSyscallEnd: event.Spec{
   206  		Name:         "GoSyscallEnd",
   207  		Args:         []string{"dt"},
   208  		StartEv:      EvGoSyscallBegin,
   209  		IsTimedEvent: true,
   210  	},
   211  	EvGoSyscallEndBlocked: event.Spec{
   212  		Name:         "GoSyscallEndBlocked",
   213  		Args:         []string{"dt"},
   214  		StartEv:      EvGoSyscallBegin,
   215  		IsTimedEvent: true,
   216  	},
   217  	EvGoStatus: event.Spec{
   218  		Name:         "GoStatus",
   219  		Args:         []string{"dt", "g", "m", "gstatus"},
   220  		IsTimedEvent: true,
   221  	},
   222  	EvSTWBegin: event.Spec{
   223  		Name:         "STWBegin",
   224  		Args:         []string{"dt", "kind_string", "stack"},
   225  		IsTimedEvent: true,
   226  		StackIDs:     []int{2},
   227  		StringIDs:    []int{1},
   228  	},
   229  	EvSTWEnd: event.Spec{
   230  		Name:         "STWEnd",
   231  		Args:         []string{"dt"},
   232  		StartEv:      EvSTWBegin,
   233  		IsTimedEvent: true,
   234  	},
   235  	EvGCActive: event.Spec{
   236  		Name:         "GCActive",
   237  		Args:         []string{"dt", "gc_seq"},
   238  		IsTimedEvent: true,
   239  		StartEv:      EvGCBegin,
   240  	},
   241  	EvGCBegin: event.Spec{
   242  		Name:         "GCBegin",
   243  		Args:         []string{"dt", "gc_seq", "stack"},
   244  		IsTimedEvent: true,
   245  		StackIDs:     []int{2},
   246  	},
   247  	EvGCEnd: event.Spec{
   248  		Name:         "GCEnd",
   249  		Args:         []string{"dt", "gc_seq"},
   250  		StartEv:      EvGCBegin,
   251  		IsTimedEvent: true,
   252  	},
   253  	EvGCSweepActive: event.Spec{
   254  		Name:         "GCSweepActive",
   255  		Args:         []string{"dt", "p"},
   256  		StartEv:      EvGCSweepBegin,
   257  		IsTimedEvent: true,
   258  	},
   259  	EvGCSweepBegin: event.Spec{
   260  		Name:         "GCSweepBegin",
   261  		Args:         []string{"dt", "stack"},
   262  		IsTimedEvent: true,
   263  		StackIDs:     []int{1},
   264  	},
   265  	EvGCSweepEnd: event.Spec{
   266  		Name:         "GCSweepEnd",
   267  		Args:         []string{"dt", "swept_value", "reclaimed_value"},
   268  		StartEv:      EvGCSweepBegin,
   269  		IsTimedEvent: true,
   270  	},
   271  	EvGCMarkAssistActive: event.Spec{
   272  		Name:         "GCMarkAssistActive",
   273  		Args:         []string{"dt", "g"},
   274  		StartEv:      EvGCMarkAssistBegin,
   275  		IsTimedEvent: true,
   276  	},
   277  	EvGCMarkAssistBegin: event.Spec{
   278  		Name:         "GCMarkAssistBegin",
   279  		Args:         []string{"dt", "stack"},
   280  		IsTimedEvent: true,
   281  		StackIDs:     []int{1},
   282  	},
   283  	EvGCMarkAssistEnd: event.Spec{
   284  		Name:         "GCMarkAssistEnd",
   285  		Args:         []string{"dt"},
   286  		StartEv:      EvGCMarkAssistBegin,
   287  		IsTimedEvent: true,
   288  	},
   289  	EvHeapAlloc: event.Spec{
   290  		Name:         "HeapAlloc",
   291  		Args:         []string{"dt", "heapalloc_value"},
   292  		IsTimedEvent: true,
   293  	},
   294  	EvHeapGoal: event.Spec{
   295  		Name:         "HeapGoal",
   296  		Args:         []string{"dt", "heapgoal_value"},
   297  		IsTimedEvent: true,
   298  	},
   299  	EvGoLabel: event.Spec{
   300  		Name:         "GoLabel",
   301  		Args:         []string{"dt", "label_string"},
   302  		IsTimedEvent: true,
   303  		StringIDs:    []int{1},
   304  	},
   305  	EvUserTaskBegin: event.Spec{
   306  		Name:         "UserTaskBegin",
   307  		Args:         []string{"dt", "task", "parent_task", "name_string", "stack"},
   308  		IsTimedEvent: true,
   309  		StackIDs:     []int{4},
   310  		StringIDs:    []int{3},
   311  	},
   312  	EvUserTaskEnd: event.Spec{
   313  		Name:         "UserTaskEnd",
   314  		Args:         []string{"dt", "task", "stack"},
   315  		IsTimedEvent: true,
   316  		StackIDs:     []int{2},
   317  	},
   318  	EvUserRegionBegin: event.Spec{
   319  		Name:         "UserRegionBegin",
   320  		Args:         []string{"dt", "task", "name_string", "stack"},
   321  		IsTimedEvent: true,
   322  		StackIDs:     []int{3},
   323  		StringIDs:    []int{2},
   324  	},
   325  	EvUserRegionEnd: event.Spec{
   326  		Name:         "UserRegionEnd",
   327  		Args:         []string{"dt", "task", "name_string", "stack"},
   328  		StartEv:      EvUserRegionBegin,
   329  		IsTimedEvent: true,
   330  		StackIDs:     []int{3},
   331  		StringIDs:    []int{2},
   332  	},
   333  	EvUserLog: event.Spec{
   334  		Name:         "UserLog",
   335  		Args:         []string{"dt", "task", "key_string", "value_string", "stack"},
   336  		IsTimedEvent: true,
   337  		StackIDs:     []int{4},
   338  		StringIDs:    []int{2, 3},
   339  	},
   340  	EvGoSwitch: event.Spec{
   341  		Name:         "GoSwitch",
   342  		Args:         []string{"dt", "g", "g_seq"},
   343  		IsTimedEvent: true,
   344  	},
   345  	EvGoSwitchDestroy: event.Spec{
   346  		Name:         "GoSwitchDestroy",
   347  		Args:         []string{"dt", "g", "g_seq"},
   348  		IsTimedEvent: true,
   349  	},
   350  	EvGoCreateBlocked: event.Spec{
   351  		Name:         "GoCreateBlocked",
   352  		Args:         []string{"dt", "new_g", "new_stack", "stack"},
   353  		IsTimedEvent: true,
   354  		StackIDs:     []int{3, 2},
   355  	},
   356  }
   357  
   358  type GoStatus uint8
   359  
   360  const (
   361  	GoBad GoStatus = iota
   362  	GoRunnable
   363  	GoRunning
   364  	GoSyscall
   365  	GoWaiting
   366  )
   367  
   368  func (s GoStatus) String() string {
   369  	switch s {
   370  	case GoRunnable:
   371  		return "Runnable"
   372  	case GoRunning:
   373  		return "Running"
   374  	case GoSyscall:
   375  		return "Syscall"
   376  	case GoWaiting:
   377  		return "Waiting"
   378  	}
   379  	return "Bad"
   380  }
   381  
   382  type ProcStatus uint8
   383  
   384  const (
   385  	ProcBad ProcStatus = iota
   386  	ProcRunning
   387  	ProcIdle
   388  	ProcSyscall
   389  	ProcSyscallAbandoned
   390  )
   391  
   392  func (s ProcStatus) String() string {
   393  	switch s {
   394  	case ProcRunning:
   395  		return "Running"
   396  	case ProcIdle:
   397  		return "Idle"
   398  	case ProcSyscall:
   399  		return "Syscall"
   400  	}
   401  	return "Bad"
   402  }
   403  
   404  const (
   405  	// Various format-specific constants.
   406  	MaxBatchSize      = 64 << 10
   407  	MaxFramesPerStack = 128
   408  	MaxStringSize     = 1 << 10
   409  )