add profiler support

profiling is now available via the HTTP base URL /debug/pprof/

examples, use this URL to start and download a 30 seconds CPU profile:

/debug/pprof/profile?seconds=30

use this URL to profile used memory:

/debug/pprof/heap?gc=1

use this URL to profile allocated memory:

/debug/pprof/allocs?gc=1

Full docs here:

https://golang.org/pkg/net/http/pprof/
This commit is contained in:
Nicola Murino
2020-03-15 15:16:35 +01:00
parent f4e872c782
commit 81c8e8d898
9 changed files with 44 additions and 12 deletions

View File

@@ -41,6 +41,7 @@ type Service struct {
LogVerbose bool
PortableMode int
PortableUser dataprovider.User
Profiler bool
Shutdown chan bool
}
@@ -62,8 +63,8 @@ func (s *Service) Start() error {
}
version := utils.GetAppVersion()
logger.Info(logSender, "", "starting SFTPGo %v, config dir: %v, config file: %v, log max size: %v log max backups: %v "+
"log max age: %v log verbose: %v, log compress: %v", version.GetVersionAsString(), s.ConfigDir, s.ConfigFile, s.LogMaxSize,
s.LogMaxBackups, s.LogMaxAge, s.LogVerbose, s.LogCompress)
"log max age: %v log verbose: %v, log compress: %v, profile: %v", version.GetVersionAsString(), s.ConfigDir, s.ConfigFile,
s.LogMaxSize, s.LogMaxBackups, s.LogMaxAge, s.LogVerbose, s.LogCompress, s.Profiler)
// in portable mode we don't read configuration from file
if s.PortableMode != 1 {
config.LoadConfig(s.ConfigDir, s.ConfigFile)
@@ -105,7 +106,7 @@ func (s *Service) Start() error {
httpd.SetDataProvider(dataProvider)
go func() {
if err := httpdConf.Initialize(s.ConfigDir); err != nil {
if err := httpdConf.Initialize(s.ConfigDir, s.Profiler); err != nil {
logger.Error(logSender, "", "could not start HTTP server: %v", err)
logger.ErrorToConsole("could not start HTTP server: %v", err)
}