Source file src/internal/trace/testdata/generators/go122-syscall-steal-proc-self.go

     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  // Tests syscall P stealing.
     6  //
     7  // Specifically, it tests a scenario where a thread 'steals'
     8  // a P from itself. It's just a ProcStop with extra steps when
     9  // it happens on the same P.
    10  
    11  package main
    12  
    13  import (
    14  	"internal/trace"
    15  	"internal/trace/internal/testgen"
    16  	"internal/trace/tracev2"
    17  	"internal/trace/version"
    18  )
    19  
    20  func main() {
    21  	testgen.Main(version.Go122, gen)
    22  }
    23  
    24  func gen(t *testgen.Trace) {
    25  	t.DisableTimestamps()
    26  
    27  	g := t.Generation(1)
    28  
    29  	// A goroutine execute a syscall and steals its own P, then starts running
    30  	// on that P.
    31  	b0 := g.Batch(trace.ThreadID(0), 0)
    32  	b0.Event("ProcStatus", trace.ProcID(0), tracev2.ProcRunning)
    33  	b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), tracev2.GoRunning)
    34  	b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack)
    35  	b0.Event("ProcSteal", trace.ProcID(0), testgen.Seq(2), trace.ThreadID(0))
    36  	b0.Event("ProcStart", trace.ProcID(0), testgen.Seq(3))
    37  	b0.Event("GoSyscallEndBlocked")
    38  }
    39  

View as plain text