-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (76 loc) · 2.31 KB
/
main.go
File metadata and controls
88 lines (76 loc) · 2.31 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"os"
"runtime/pprof"
"net/http"
_ "net/http/pprof"
"github.com/alecthomas/kong"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/ylacancellera/random-data-load/cmd"
"github.com/ylacancellera/random-data-load/frequency"
"github.com/ylacancellera/random-data-load/generate"
"github.com/ylacancellera/random-data-load/query"
)
const (
toolname = "random-data-load"
)
var (
Build string //nolint
GoVersion string //nolint
Version string //nolint
Commit string //nolint
)
var buildInfo = fmt.Sprintf("%s\nVersion %s\nBuild: %s using %s\nCommit: %s", toolname, Version, Build, GoVersion, Commit)
var cli struct {
Run cmd.RunCmd `cmd:"run" help:"Starts the insert process"`
Query cmd.QueryCmd `cmd:"query" help:"Providing a query will analyze its schema usage, insert recursively into tables, and identify implicit joins"`
Version kong.VersionFlag
Profile bool `name:"pprof" help:"generate pprof trace at --cpu-prof-path. Also opens port 6060 for pprof go tool"`
CPUProfPath string `name:"cpu-prof-path" default:"cpu.prof"`
Debug bool `name:"debug"`
}
func main() {
kongcli := kong.Parse(&cli,
kong.Name(toolname),
kong.Description("Load random data into a table"),
kong.UsageOnError(),
kong.ValueMapper(&cli.Run.AddForeignKeys, query.VirtualJoins{}),
kong.ValueMapper(&cli.Run.NullFreqMap, &frequency.FrequencyNullParameter{}),
kong.ValueMapper(&cli.Run.ValuesFreqMap, &frequency.FrequencyIndexValuesParameter{}),
kong.Vars{
"version": buildInfo,
"SequentialFlag": generate.SequentialFlag,
"BinomialFlag": generate.BinomialFlag,
},
kong.ConfigureHelp(kong.HelpOptions{
Compact: false,
Summary: true,
Tree: true,
}),
)
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if cli.Debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
if cli.Profile {
f, err := os.Create(cli.CPUProfPath)
if err != nil {
panic(err)
}
defer f.Close()
// for other types of profiles like mutexes, mem
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
// Start CPU profiling
if err := pprof.StartCPUProfile(f); err != nil {
panic(err)
}
defer pprof.StopCPUProfile()
}
err := kongcli.Run()
kongcli.FatalIfErrorf(err)
}