forked from valyala/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Similar to expvarhandler but for net/http/pprof
- Loading branch information
1 parent
bcb67ca
commit 45018c4
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
45018c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @erikdubbelboer