Add more advanced profiling support

This commit is contained in:
Dane Everitt 2020-11-08 12:12:21 -08:00
parent 536f00a5e5
commit 1683675807
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -31,10 +31,9 @@ import (
) )
var ( var (
profiler = ""
configPath = config.DefaultLocation configPath = config.DefaultLocation
debug = false debug = false
runCPUProfile = false
runMemProfile = false
useAutomaticTls = false useAutomaticTls = false
tlsHostname = "" tlsHostname = ""
showVersion = false showVersion = false
@ -57,8 +56,7 @@ func init() {
root.PersistentFlags().BoolVar(&showVersion, "version", false, "show the version and exit") root.PersistentFlags().BoolVar(&showVersion, "version", false, "show the version and exit")
root.PersistentFlags().StringVar(&configPath, "config", config.DefaultLocation, "set the location for the configuration file") root.PersistentFlags().StringVar(&configPath, "config", config.DefaultLocation, "set the location for the configuration file")
root.PersistentFlags().BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode") root.PersistentFlags().BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode")
root.PersistentFlags().BoolVar(&runCPUProfile, "profile-cpu", false, "pass in order to profile wings CPU usage") root.PersistentFlags().StringVar(&profiler, "profiler", "", "the profiler to run for this instance")
root.PersistentFlags().BoolVar(&runMemProfile, "profile-mem", false, "pass in order to profile wings memory usage")
root.PersistentFlags().BoolVar(&useAutomaticTls, "auto-tls", false, "pass in order to have wings generate and manage it's own SSL certificates using Let's Encrypt") root.PersistentFlags().BoolVar(&useAutomaticTls, "auto-tls", false, "pass in order to have wings generate and manage it's own SSL certificates using Let's Encrypt")
root.PersistentFlags().StringVar(&tlsHostname, "tls-hostname", "", "required with --auto-tls, the FQDN for the generated SSL certificate") root.PersistentFlags().StringVar(&tlsHostname, "tls-hostname", "", "required with --auto-tls, the FQDN for the generated SSL certificate")
@ -93,16 +91,23 @@ func rootCmdRun(*cobra.Command, []string) {
os.Exit(0) os.Exit(0)
} }
if runCPUProfile { switch profiler {
defer profile.Start(func(p *profile.Profile) { case "cpu":
profile.CPUProfile(p) profile.Start(profile.CPUProfile)
}).Stop() case "mem":
} profile.Start(profile.MemProfile)
case "alloc":
if runMemProfile { profile.Start(profile.MemProfileAllocs())
defer profile.Start(func(p *profile.Profile) { case "heap":
profile.MemProfile(p) profile.Start(profile.MemProfileHeap())
}).Stop() case "routines":
profile.Start(profile.GoroutineProfile)
case "mutex":
profile.Start(profile.MutexProfile)
case "threads":
profile.Start(profile.ThreadcreationProfile)
case "block":
profile.Start(profile.BlockProfile)
} }
// Only attempt configuration file relocation if a custom location has not // Only attempt configuration file relocation if a custom location has not