frostfs-s3-gw/cmd/s3-gw/app-profiler.go

33 lines
807 B
Go
Raw Normal View History

2020-07-06 09:18:16 +00:00
package main
import (
"net/http/pprof"
"github.com/gorilla/mux"
"github.com/spf13/viper"
2020-07-12 23:00:47 +00:00
"go.uber.org/zap"
2020-07-06 09:18:16 +00:00
)
func attachProfiler(r *mux.Router, v *viper.Viper, l *zap.Logger) {
2020-07-07 11:25:13 +00:00
if !v.GetBool(cfgEnableProfiler) {
2020-07-06 09:18:16 +00:00
return
}
2020-07-12 23:00:47 +00:00
l.Info("enable profiler")
profiler := r.PathPrefix(systemPath + "/debug/pprof").
Subrouter().
StrictSlash(true)
profiler.HandleFunc("/", pprof.Index)
profiler.HandleFunc("/cmdline", pprof.Cmdline)
profiler.HandleFunc("/profile", pprof.Profile)
profiler.HandleFunc("/symbol", pprof.Symbol)
profiler.HandleFunc("/trace", pprof.Trace)
// Manually add support for paths linked to by index page at /debug/pprof/
for _, item := range []string{"allocs", "block", "heap", "goroutine", "mutex", "threadcreate"} {
profiler.Handle("/"+item, pprof.Handler(item))
}
2020-07-06 09:18:16 +00:00
}