Add support for proper use of pprof
This commit is contained in:
parent
1965e68a78
commit
c3df8d2309
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -49,3 +49,4 @@ debug
|
|||
.DS_Store
|
||||
*.pprof
|
||||
*.pdf
|
||||
pprof.*
|
32
cmd/root.go
32
cmd/root.go
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
log2 "log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -20,7 +21,6 @@ import (
|
|||
"github.com/docker/docker/client"
|
||||
"github.com/gammazero/workerpool"
|
||||
"github.com/mitchellh/colorstring"
|
||||
"github.com/pkg/profile"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/crypto/acme"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
|
@ -75,7 +75,8 @@ func init() {
|
|||
rootCommand.PersistentFlags().BoolVar(&debug, "debug", false, "pass in order to run wings in debug mode")
|
||||
|
||||
// Flags specifically used when running the API.
|
||||
rootCommand.Flags().String("profiler", "", "the profiler to run for this instance")
|
||||
rootCommand.Flags().Bool("pprof", false, "if the pprof profiler should be enabled. The profiler will bind to localhost:6060 by default")
|
||||
rootCommand.Flags().Int("pprof-port", 6060, "If provided with --pprof, the port it will run on")
|
||||
rootCommand.Flags().Bool("auto-tls", false, "pass in order to have wings generate and manage it's own SSL certificates using Let's Encrypt")
|
||||
rootCommand.Flags().String("tls-hostname", "", "required with --auto-tls, the FQDN for the generated SSL certificate")
|
||||
rootCommand.Flags().Bool("ignore-certificate-errors", false, "ignore certificate verification errors when executing API calls")
|
||||
|
@ -86,25 +87,6 @@ func init() {
|
|||
}
|
||||
|
||||
func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||
switch cmd.Flag("profiler").Value.String() {
|
||||
case "cpu":
|
||||
defer profile.Start(profile.CPUProfile).Stop()
|
||||
case "mem":
|
||||
defer profile.Start(profile.MemProfile).Stop()
|
||||
case "alloc":
|
||||
defer profile.Start(profile.MemProfile, profile.MemProfileAllocs).Stop()
|
||||
case "heap":
|
||||
defer profile.Start(profile.MemProfile, profile.MemProfileHeap).Stop()
|
||||
case "routines":
|
||||
defer profile.Start(profile.GoroutineProfile).Stop()
|
||||
case "mutex":
|
||||
defer profile.Start(profile.MutexProfile).Stop()
|
||||
case "threads":
|
||||
defer profile.Start(profile.ThreadcreationProfile).Stop()
|
||||
case "block":
|
||||
defer profile.Start(profile.BlockProfile).Stop()
|
||||
}
|
||||
|
||||
printLogo()
|
||||
log.Debug("running in debug mode")
|
||||
log.WithField("config_file", configPath).Info("loading configuration from file")
|
||||
|
@ -325,6 +307,14 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
|||
TLSConfig: config.DefaultTLSConfig,
|
||||
}
|
||||
|
||||
profile, _ := cmd.Flags().GetBool("pprof")
|
||||
if profile {
|
||||
profilePort, _ := cmd.Flags().GetInt("pprof-port")
|
||||
go func() {
|
||||
http.ListenAndServe(fmt.Sprintf("localhost:%d", profilePort), nil)
|
||||
}()
|
||||
}
|
||||
|
||||
// Check if the server should run with TLS but using autocert.
|
||||
if autotls {
|
||||
m := autocert.Manager{
|
||||
|
|
Loading…
Reference in New Issue
Block a user