frostfs-s3-gw/cmd/s3-gw/app-profiler.go
Roman Khimov e622f1987b Makefile: deduplicate binaries
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2021-05-20 16:26:20 +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))
}
}