CPU profiling (#1371)

* Add cpuprofile flag
* Add notes to readme
This commit is contained in:
WithoutPants
2021-05-16 17:21:11 +10:00
committed by GitHub
parent bc9aa02835
commit 16fe21138f
5 changed files with 59 additions and 5 deletions

View File

@@ -17,18 +17,20 @@ var once sync.Once
type flagStruct struct {
configFilePath string
cpuProfilePath string
}
func Initialize() (*Instance, error) {
var err error
once.Do(func() {
instance = &Instance{}
flags := initFlags()
instance = &Instance{
cpuProfilePath: flags.cpuProfilePath,
}
if err = initConfig(flags); err != nil {
return
}
initEnvs()
if instance.isNewSystem {
@@ -46,6 +48,7 @@ func Initialize() (*Instance, error) {
}
func initConfig(flags flagStruct) error {
// The config file is called config. Leave off the file extension.
viper.SetConfigName("config")
@@ -98,6 +101,7 @@ func initFlags() flagStruct {
pflag.IP("host", net.IPv4(0, 0, 0, 0), "ip address for the host")
pflag.Int("port", 9999, "port to serve from")
pflag.StringVarP(&flags.configFilePath, "config", "c", "", "config file to use")
pflag.StringVar(&flags.cpuProfilePath, "cpuprofile", "", "write cpu profile to file")
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {