Add more advanced profiling support
This commit is contained in:
parent
536f00a5e5
commit
1683675807
33
cmd/root.go
33
cmd/root.go
|
@ -31,10 +31,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
profiler = ""
|
||||
configPath = config.DefaultLocation
|
||||
debug = false
|
||||
runCPUProfile = false
|
||||
runMemProfile = false
|
||||
useAutomaticTls = false
|
||||
tlsHostname = ""
|
||||
showVersion = false
|
||||
|
@ -57,8 +56,7 @@ func init() {
|
|||
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().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().BoolVar(&runMemProfile, "profile-mem", false, "pass in order to profile wings memory usage")
|
||||
root.PersistentFlags().StringVar(&profiler, "profiler", "", "the profiler to run for this instance")
|
||||
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")
|
||||
|
||||
|
@ -93,16 +91,23 @@ func rootCmdRun(*cobra.Command, []string) {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
if runCPUProfile {
|
||||
defer profile.Start(func(p *profile.Profile) {
|
||||
profile.CPUProfile(p)
|
||||
}).Stop()
|
||||
}
|
||||
|
||||
if runMemProfile {
|
||||
defer profile.Start(func(p *profile.Profile) {
|
||||
profile.MemProfile(p)
|
||||
}).Stop()
|
||||
switch profiler {
|
||||
case "cpu":
|
||||
profile.Start(profile.CPUProfile)
|
||||
case "mem":
|
||||
profile.Start(profile.MemProfile)
|
||||
case "alloc":
|
||||
profile.Start(profile.MemProfileAllocs())
|
||||
case "heap":
|
||||
profile.Start(profile.MemProfileHeap())
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user