mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Add support for named profiles like heap, goroutine, threadcreate, allocs, block, and mutex.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user