-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_profiles.go
30 lines (25 loc) · 1.07 KB
/
debug_profiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package go_webserver
import (
httpprof "net/http/pprof"
"runtime/pprof"
"strings"
)
// -----------------------------------------------------------------------------
// ServeDebugProfiles adds the GO runtime profile handlers to a web server
func (srv *Server) ServeDebugProfiles(basePath string, middlewares ...HandlerFunc) {
if !strings.HasPrefix(basePath, "/") {
basePath = "/" + basePath
}
if !strings.HasSuffix(basePath, "/") {
basePath = basePath + "/"
}
srv.GET(basePath, NewHandlerFromHttpHandlerFunc(httpprof.Index), middlewares...)
for _, profile := range pprof.Profiles() {
h := httpprof.Handler(profile.Name())
srv.GET(basePath+profile.Name(), NewHandlerFromHttpHandler(h), middlewares...)
}
srv.GET(basePath+"cmdline", NewHandlerFromHttpHandlerFunc(httpprof.Cmdline), middlewares...)
srv.GET(basePath+"profile", NewHandlerFromHttpHandlerFunc(httpprof.Profile), middlewares...)
srv.GET(basePath+"symbol", NewHandlerFromHttpHandlerFunc(httpprof.Symbol), middlewares...)
srv.GET(basePath+"trace", NewHandlerFromHttpHandlerFunc(httpprof.Trace), middlewares...)
}