golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/testdata/generators/go122-syscall-steal-proc-ambiguous.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  // Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.
     6  
     7  //go:build go1.21
     8  
     9  // Tests syscall P stealing.
    10  //
    11  // Specifically, it tests a scenerio wherein, without a
    12  // P sequence number of GoSyscallBegin, the syscall that
    13  // a ProcSteal applies to is ambiguous. This only happens in
    14  // practice when the events aren't already properly ordered
    15  // by timestamp, since the ProcSteal won't be seen until after
    16  // the correct GoSyscallBegin appears on the frontier.
    17  
    18  package main
    19  
    20  import (
    21  	"golang.org/x/exp/trace"
    22  	"golang.org/x/exp/trace/internal/event/go122"
    23  	testgen "golang.org/x/exp/trace/internal/testgen/go122"
    24  )
    25  
    26  func main() {
    27  	testgen.Main(gen)
    28  }
    29  
    30  func gen(t *testgen.Trace) {
    31  	t.DisableTimestamps()
    32  
    33  	g := t.Generation(1)
    34  
    35  	// One goroutine does a syscall without blocking, then another one where
    36  	// it's P gets stolen.
    37  	b0 := g.Batch(trace.ThreadID(0), 0)
    38  	b0.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning)
    39  	b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning)
    40  	b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack)
    41  	b0.Event("GoSyscallEnd")
    42  	b0.Event("GoSyscallBegin", testgen.Seq(2), testgen.NoStack)
    43  	b0.Event("GoSyscallEndBlocked")
    44  
    45  	// A running goroutine steals proc 0.
    46  	b1 := g.Batch(trace.ThreadID(1), 0)
    47  	b1.Event("ProcStatus", trace.ProcID(2), go122.ProcRunning)
    48  	b1.Event("GoStatus", trace.GoID(2), trace.ThreadID(1), go122.GoRunning)
    49  	b1.Event("ProcSteal", trace.ProcID(0), testgen.Seq(3), trace.ThreadID(0))
    50  }