Debian Codegraph @

src/runtime/testdata/testgoroutineleakprofile/main.go

raw
1 // Copyright 2025 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 main
6
7 import "os"
8
9 // The number of times the main (profiling) goroutine should yield
10 // in order to allow the leaking goroutines to get stuck.
11 const yieldCount = 10
12
13 var cmds = map[string]func(){}
14
15 func register(name string, f func()) {
16 if cmds[name] != nil {
17 panic("duplicate registration: " + name)
18 }
19 cmds[name] = f
20 }
21
22 func registerInit(name string, f func()) {
23 if len(os.Args) >= 2 && os.Args[1] == name {
24 f()
25 }
26 }
27
28 func main() {
29 if len(os.Args) < 2 {
30 println("usage: " + os.Args[0] + " name-of-test")
31 return
32 }
33 f := cmds[os.Args[1]]
34 if f == nil {
35 println("unknown function: " + os.Args[1])
36 return
37 }
38 f()
39 }