From 33b80a5951ab04016906983ada65a0b31fb5ce57 Mon Sep 17 00:00:00 2001 From: mmta Date: Sat, 29 Sep 2018 15:38:12 +0700 Subject: [PATCH] Add support for named profiles like heap, goroutine, threadcreate, allocs, block, and mutex. --- pprofhandler/pprof.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pprofhandler/pprof.go b/pprofhandler/pprof.go index 200ae51..c94d2c1 100644 --- a/pprofhandler/pprof.go +++ b/pprofhandler/pprof.go @@ -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) } }