-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (53 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"os"
"runtime/pprof"
"github.com/alecthomas/kong"
"github.com/gentoomaniac/logging"
"github.com/rs/zerolog/log"
)
var (
version = "0.0.1"
)
var cli struct {
logging.LoggingConfig
Bot []string `short:"b" help:"add another bot with this filename to the arena" required:""`
Respawns int `short:"r" help:"Number of respawns"`
ProfileMemory string `help:"write a memory profile"`
ProfileCPU string `help:"write a cpu profile"`
Version kong.VersionFlag `short:"v" help:"Display version."`
}
func main() {
ctx := kong.Parse(&cli, kong.UsageOnError(), kong.Vars{
"version": version,
})
logging.Setup(&cli.LoggingConfig)
log.Info().Msg("Starting game")
if cli.ProfileCPU != "" {
f, err := os.Create(cli.ProfileCPU)
if err != nil {
log.Error().Err(err).Msg("could not create cpu profile")
ctx.Exit(1)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Error().Err(err).Msg("could not start cpu profile")
ctx.Exit(1)
}
defer pprof.StopCPUProfile()
}
run(cli.Bot)
if cli.ProfileMemory != "" {
f, err := os.Create(cli.ProfileMemory)
if err != nil {
log.Error().Err(err).Msg("could not create memory profile")
ctx.Exit(1)
}
defer f.Close()
if err := pprof.WriteHeapProfile(f); err != nil {
log.Error().Err(err).Msg("could not start memory profile")
ctx.Exit(1)
}
}
pprof.StopCPUProfile()
ctx.Exit(0)
}