mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
util: enable golang profiling
Add support for golang profiling. Standard tools like go tool pprof and curl work. example: $ go tool pprof http://localhost:8080/debug/pprof/profile $ go tool pprof http://localhost:8080/debug/pprof/heap $ curl http://localhost:8080/debug/pprof/heap?debug=1 https://golang.org/pkg/net/http/pprof/ contains more details about the pprof interface. Fixes: #1699 Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
@ -3,7 +3,9 @@ package util
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"net/url"
|
||||
runtime_pprof "runtime/pprof"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@ -24,3 +26,22 @@ func StartMetricsServer(c *Config) {
|
||||
FatalLogMsg("failed to listen on address %v: %s", addr, err)
|
||||
}
|
||||
}
|
||||
func addPath(name string, handler http.Handler) {
|
||||
http.Handle(name, handler)
|
||||
DebugLogMsg("DEBUG: registered profiling handler on /debug/pprof/%s\n", name)
|
||||
}
|
||||
|
||||
// EnableProfiling enables golang profiling.
|
||||
func EnableProfiling() {
|
||||
for _, profile := range runtime_pprof.Profiles() {
|
||||
name := profile.Name()
|
||||
handler := pprof.Handler(name)
|
||||
addPath(name, handler)
|
||||
}
|
||||
|
||||
// static profiles as listed in net/http/pprof/pprof.go:init()
|
||||
addPath("cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||
addPath("profile", http.HandlerFunc(pprof.Profile))
|
||||
addPath("symbol", http.HandlerFunc(pprof.Symbol))
|
||||
addPath("trace", http.HandlerFunc(pprof.Trace))
|
||||
}
|
||||
|
Reference in New Issue
Block a user