github.com/ice-blockchain/go/src@v0.0.0-20240403114104-1564d284e521/internal/trace/v2/testdata/generators/go122-syscall-steal-proc-self.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 // 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/v2" 15 "internal/trace/v2/event/go122" 16 testgen "internal/trace/v2/internal/testgen/go122" 17 ) 18 19 func main() { 20 testgen.Main(gen) 21 } 22 23 func gen(t *testgen.Trace) { 24 t.DisableTimestamps() 25 26 g := t.Generation(1) 27 28 // A goroutine execute a syscall and steals its own P, then starts running 29 // on that P. 30 b0 := g.Batch(trace.ThreadID(0), 0) 31 b0.Event("ProcStatus", trace.ProcID(0), go122.ProcRunning) 32 b0.Event("GoStatus", trace.GoID(1), trace.ThreadID(0), go122.GoRunning) 33 b0.Event("GoSyscallBegin", testgen.Seq(1), testgen.NoStack) 34 b0.Event("ProcSteal", trace.ProcID(0), testgen.Seq(2), trace.ThreadID(0)) 35 b0.Event("ProcStart", trace.ProcID(0), testgen.Seq(3)) 36 b0.Event("GoSyscallEndBlocked") 37 }