From 54c85c2a65be58e6f0ebf395da83bad0c37a6346 Mon Sep 17 00:00:00 2001 From: Botond Sipos Date: Sun, 31 May 2020 10:46:42 +0100 Subject: [PATCH] Added options for setting GOMAXPROCS and profiling output. --- config.go | 6 ++++++ config/config.go | 2 ++ main.go | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/config.go b/config.go index 8a18793..86939e7 100644 --- a/config.go +++ b/config.go @@ -28,6 +28,8 @@ func getConfig() *config.Config { shell := "" debugMode := false slomo := false + threads := 4 + prof := "" if flag.Parsed() == false { flag.BoolVar(&showVersion, "version", showVersion, "Output version information") @@ -35,6 +37,8 @@ func getConfig() *config.Config { flag.StringVar(&shell, "shell", shell, "Specify the shell to use") flag.BoolVar(&debugMode, "debug", debugMode, "Enable debug logging") flag.BoolVar(&slomo, "slomo", slomo, "Render in slow motion (useful for debugging)") + flag.IntVar(&threads, "threads", threads, "Number of threads to use") + flag.StringVar(&prof, "prof", prof, "Run profiler and dump info to specifed file") flag.Parse() // actual parsing and fetching flags from the command line } @@ -55,6 +59,8 @@ func getConfig() *config.Config { } else { conf = loadConfigFile() } + conf.Prof = prof + conf.Threads = threads // Override values in the configuration file with the values specified in the command line, if any. if actuallyProvidedFlags["shell"] { diff --git a/config/config.go b/config/config.go index 890892c..7296c51 100644 --- a/config/config.go +++ b/config/config.go @@ -16,6 +16,8 @@ type Config struct { SearchURL string `toml:"search_url"` MaxLines uint64 `toml:"max_lines"` CopyAndPasteWithMouse bool `toml:"copy_and_paste_with_mouse"` + Prof string `toml:"prof"` + Threads int `toml:"threads"` } type KeyMappingConfig map[string]string diff --git a/main.go b/main.go index aff7af0..0ee7fca 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/riywo/loginshell" "os" "runtime" + "runtime/pprof" ) type callback func(terminal *terminal.Terminal, g *gui.GUI) @@ -23,6 +24,16 @@ func main() { func initialize(unitTestfunc callback) { conf := getConfig() logger, err := getLogger(conf) + runtime.GOMAXPROCS(conf.Threads) + if conf.Prof != "" { + f, err := os.Create(conf.Prof) + defer f.Close() + if err != nil { + logger.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } if err != nil { fmt.Printf("Failed to create logger: %s\n", err) os.Exit(1)