Add support for named profiles like heap, goroutine, threadcreate, allocs, block, and mutex.

This commit is contained in:
mmta
2018-09-29 15:38:12 +07:00
committed by Kirill Danshin
parent 4087354082
commit 33b80a5951
+9
View File
@@ -2,6 +2,7 @@ package pprofhandler
import (
"net/http/pprof"
rtp "runtime/pprof"
"strings"
"github.com/valyala/fasthttp"
@@ -30,6 +31,14 @@ func PprofHandler(ctx *fasthttp.RequestCtx) {
} else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/trace") {
trace(ctx)
} else {
for _, v := range rtp.Profiles() {
ppName := v.Name()
if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/"+ppName) {
namedHandler := fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Handler(ppName).ServeHTTP)
namedHandler(ctx)
return
}
}
index(ctx)
}
}