Add an option --pprof

Former-commit-id: 3ca1280e8daddbf1075e3189f9851211ce8882ae
This commit is contained in:
2023-03-28 20:07:26 +07:00
parent 988ae79989
commit e863dc456a
3 changed files with 24 additions and 9 deletions

View File

@ -8,12 +8,17 @@ import (
log "github.com/sirupsen/logrus"
"github.com/DavidGamba/go-getoptions"
"net/http"
_ "net/http/pprof"
)
var _Debug = false
var _ParallelWorkers = runtime.NumCPU()*2 - 1
var _MaxAllowedCPU = runtime.NumCPU()
var _BatchSize = 5000
var _Pprof = false
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
@ -24,6 +29,7 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
options.SetUnknownMode(getoptions.Fail)
options.Bool("help", false, options.Alias("h", "?"))
options.BoolVar(&_Debug, "debug", false)
options.BoolVar(&_Pprof, "pprof", false)
options.IntVar(&_ParallelWorkers, "workers", _ParallelWorkers,
options.Alias("w"),
@ -52,6 +58,11 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
log.Debugln("Switch to debug level logging")
}
if options.Called("pprof") {
go http.ListenAndServe("localhost:8080", nil)
log.Infoln("Start a pprof server at address http://localhost:8080/debug/pprof")
}
// Handle user errors
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)