frostfs-s3-gw/cmd/s3-gw/app_profiler.go
Denis Kirillov bf3d81f928 [] Unify source file naming
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2021-08-20 15:19:49 +03:00

32 lines
807 B
Go

package main
import (
"net/http/pprof"
"github.com/gorilla/mux"
"github.com/spf13/viper"
"go.uber.org/zap"
)
func attachProfiler(r *mux.Router, v *viper.Viper, l *zap.Logger) {
if !v.GetBool(cfgEnableProfiler) {
return
}
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))
}
}