github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/trace/goroutines.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  package trace
     6  
     7  // GDesc contains statistics and execution details of a single goroutine.
     8  type GDesc struct {
     9  	ID           uint64
    10  	Name         string
    11  	PC           uint64
    12  	CreationTime int64
    13  	StartTime    int64
    14  	EndTime      int64
    15  
    16  	// List of regions in the goroutine, sorted based on the start time.
    17  	Regions []*UserRegionDesc
    18  
    19  	// Statistics of execution time during the goroutine execution.
    20  	GExecutionStat
    21  
    22  	*gdesc
    23  }
    24  
    25  // UserRegionDesc represents a region and goroutine execution stats
    26  // while the region was active.
    27  type UserRegionDesc struct {
    28  	TaskID uint64
    29  	Name   string
    30  
    31  	// Region start event. Normally EvUserRegion start event or nil,
    32  	// but can be EvGoCreate event if the region is a synthetic
    33  	// region representing task inheritance from the parent goroutine.
    34  	Start *Event
    35  
    36  	// Region end event. Normally EvUserRegion end event or nil,
    37  	// but can be EvGoStop or EvGoEnd event if the goroutine
    38  	// terminated without explicitly ending the region.
    39  	End *Event
    40  
    41  	GExecutionStat
    42  }
    43  
    44  // GExecutionStat contains statistics about a goroutine's execution
    45  // during a period of time.
    46  type GExecutionStat struct {
    47  	ExecTime      int64
    48  	SchedWaitTime int64
    49  	IOTime        int64
    50  	BlockTime     int64
    51  	SyscallTime   int64
    52  	GCTime        int64
    53  	SweepTime     int64
    54  	TotalTime     int64
    55  }
    56  
    57  // GoroutineStats generates statistics for all goroutines in the trace.
    58  func GoroutineStats(events []*Event) map[uint64]*GDesc
    59  
    60  // RelatedGoroutines finds a set of goroutines related to goroutine goid.
    61  func RelatedGoroutines(events []*Event, goid uint64) map[uint64]bool
    62  
    63  func IsSystemGoroutine(entryFn string) bool