-
Notifications
You must be signed in to change notification settings - Fork 0
/
pprof.go
38 lines (36 loc) · 1.03 KB
/
pprof.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
31
32
33
34
35
36
37
38
package main
import (
"net/http"
"net/http/pprof"
)
// ProfileMiddleware is a middleware that handles pprof requests.
func ProfileMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/debug/pprof/":
pprof.Cmdline(w, req)
case "/debug/pprof/cmdline":
pprof.Cmdline(w, req)
case "/debug/pprof/profile":
pprof.Profile(w, req)
case "/debug/pprof/symbol":
pprof.Symbol(w, req)
case "/debug/pprof/trace":
pprof.Trace(w, req)
case "/debug/pprof/allocs":
pprof.Handler("allocs").ServeHTTP(w, req)
case "/debug/pprof/block":
pprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
pprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/heap":
pprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/mutex":
pprof.Handler("mutex").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
pprof.Handler("threadcreate").ServeHTTP(w, req)
default:
next.ServeHTTP(w, req)
}
})
}