QA-Pilot
QA-Pilot copied to clipboard
generics in Go codegraph
Generics in Go, so far cannot make a associate with below situation:
src/cmd/trace/gstate.go
type gState[R resource] struct {
baseName string
named bool // Whether baseName has been set.
label string // EventLabel extension.
isSystemG bool
executing R // The resource this goroutine is executing on. (Could be itself.)
.....
}
func (gs *gState[R]) setStartCause(ts trace.Time, name string, resource uint64, stack trace.Stack) {
gs.startCause.time = ts
gs.startCause.name = name
gs.startCause.resource = resource
gs.startCause.stack = stack
}
// created indicates that this goroutine was just created by the provided creator.
func (gs *gState[R]) created(ts trace.Time, creator R, stack trace.Stack) {
if creator == R(noResource) {
return
}
gs.setStartCause(ts, "go", uint64(creator), stack)
}
// start indicates that a goroutine has started running on a proc.
func (gs *gState[R]) start(ts trace.Time, resource R, ctx *traceContext) {
// Set the time for all the active ranges.
for name := range gs.activeRanges {
gs.activeRanges[name] = activeRange{ts, trace.NoStack}
}
if gs.startCause.name != "" {
// It has a start cause. Emit a flow event.
ctx.Arrow(traceviewer.ArrowEvent{
Name: gs.startCause.name,
Start: ctx.elapsed(gs.startCause.time),
End: ctx.elapsed(ts),
FromResource: uint64(gs.startCause.resource),
ToResource: uint64(resource),
FromStack: ctx.Stack(viewerFrames(gs.startCause.stack)),
})
gs.startCause.time = 0
gs.startCause.name = ""
gs.startCause.resource = 0
gs.startCause.stack = trace.NoStack
}
gs.executing = resource
gs.startRunningTime = ts
}