forked from gin-gonic/gin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug_pprof.go
41 lines (37 loc) · 1.33 KB
/
debug_pprof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package gin
import (
"github.com/chanxuehong/gin/pprof"
)
// DebugPProf registers internal HandlerFunc to process path "/debug/pprof/*name", for more information please see net/http/pprof.
//
// Please NOTE that DebugPProf does not use any middleware of Engine, you can specify middlewares optionally when you call this method.
func (engine *Engine) DebugPProf(middleware ...HandlerFunc) {
for _, h := range middleware {
if h == nil {
panic("each middleware can not be nil")
}
}
engine.startedChecker.check() // check if engine has been started.
handlers := combineHandlerChain(middleware, HandlerChain{debugPProfHandler})
for _, method := range __httpMethods {
engine.addRoute(method, "/debug/pprof/*name", handlers)
}
}
func debugPProfHandler(ctx *Context) {
path := ctx.Request.URL.Path
switch path {
default:
pprof.Index(ctx.ResponseWriter, ctx.Request)
case "/debug/pprof/cmdline":
pprof.Cmdline(ctx.ResponseWriter, ctx.Request)
case "/debug/pprof/profile":
pprof.Profile(ctx.ResponseWriter, ctx.Request)
case "/debug/pprof/symbol":
pprof.Symbol(ctx.ResponseWriter, ctx.Request)
case "/debug/pprof/trace":
pprof.Trace(ctx.ResponseWriter, ctx.Request)
}
}