diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2017-03-14 05:31:42 +0000 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2018-08-17 17:04:14 +0800 |
commit | 074e62ddb04009e267daf5f25b3538b568602826 (patch) | |
tree | 1cffa0b52c96526dc13d6e402169d408b7450f5a /pprofhandler | |
parent | Merge pull request #303 from chebyrash/master (diff) | |
download | fasthttp-074e62ddb04009e267daf5f25b3538b568602826.tar.gz fasthttp-074e62ddb04009e267daf5f25b3538b568602826.tar.bz2 fasthttp-074e62ddb04009e267daf5f25b3538b568602826.zip |
Add pprofhandler, fix #235
Similar to expvarhandler but for net/http/pprof
Diffstat (limited to 'pprofhandler')
-rw-r--r-- | pprofhandler/pprof.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pprofhandler/pprof.go b/pprofhandler/pprof.go new file mode 100644 index 0000000..200ae51 --- /dev/null +++ b/pprofhandler/pprof.go @@ -0,0 +1,35 @@ +package pprofhandler + +import ( + "net/http/pprof" + "strings" + + "github.com/valyala/fasthttp" + "github.com/valyala/fasthttp/fasthttpadaptor" +) + +var ( + cmdline = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Cmdline) + profile = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Profile) + symbol = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Symbol) + trace = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Trace) + index = fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Index) +) + +// PprofHandler serves server runtime profiling data in the format expected by the pprof visualization tool. +// +// See https://golang.org/pkg/net/http/pprof/ for details. +func PprofHandler(ctx *fasthttp.RequestCtx) { + ctx.Response.Header.Set("Content-Type", "text/html") + if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/cmdline") { + cmdline(ctx) + } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/profile") { + profile(ctx) + } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/symbol") { + symbol(ctx) + } else if strings.HasPrefix(string(ctx.Path()), "/debug/pprof/trace") { + trace(ctx) + } else { + index(ctx) + } +} |