mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Former-commit-id: 752a788263f8bd9219690b3b63b1183546fb91e5
This commit is contained in:
parent
b22151d4b7
commit
59f138963b
|
@ -2,7 +2,9 @@
|
|||
package pprof
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http/pprof"
|
||||
rpprof "runtime/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
|
@ -12,7 +14,6 @@ import (
|
|||
// New returns a new pprof (profile, cmdline, symbol, goroutine, heap, threadcreate, debug/block) Middleware.
|
||||
// Note: Route MUST have the last named parameter wildcard named '{action:path}'
|
||||
func New() context.Handler {
|
||||
indexHandler := handlerconv.FromStd(pprof.Index)
|
||||
cmdlineHandler := handlerconv.FromStd(pprof.Cmdline)
|
||||
profileHandler := handlerconv.FromStd(pprof.Profile)
|
||||
symbolHandler := handlerconv.FromStd(pprof.Symbol)
|
||||
|
@ -23,25 +24,54 @@ func New() context.Handler {
|
|||
|
||||
return func(ctx context.Context) {
|
||||
ctx.ContentType("text/html")
|
||||
actionPathParameter := ctx.Values().GetString("action")
|
||||
if len(actionPathParameter) > 1 {
|
||||
if strings.Contains(actionPathParameter, "cmdline") {
|
||||
action := ctx.Params().Get("action")
|
||||
if action != "" {
|
||||
if strings.Contains(action, "cmdline") {
|
||||
cmdlineHandler((ctx))
|
||||
} else if strings.Contains(actionPathParameter, "profile") {
|
||||
} else if strings.Contains(action, "profile") {
|
||||
profileHandler(ctx)
|
||||
} else if strings.Contains(actionPathParameter, "symbol") {
|
||||
} else if strings.Contains(action, "symbol") {
|
||||
symbolHandler(ctx)
|
||||
} else if strings.Contains(actionPathParameter, "goroutine") {
|
||||
} else if strings.Contains(action, "goroutine") {
|
||||
goroutineHandler(ctx)
|
||||
} else if strings.Contains(actionPathParameter, "heap") {
|
||||
} else if strings.Contains(action, "heap") {
|
||||
heapHandler(ctx)
|
||||
} else if strings.Contains(actionPathParameter, "threadcreate") {
|
||||
} else if strings.Contains(action, "threadcreate") {
|
||||
threadcreateHandler(ctx)
|
||||
} else if strings.Contains(actionPathParameter, "debug/block") {
|
||||
} else if strings.Contains(action, "debug/block") {
|
||||
debugBlockHandler(ctx)
|
||||
}
|
||||
} else {
|
||||
indexHandler(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
profiles := rpprof.Profiles()
|
||||
data := map[string]interface{}{
|
||||
"Profiles": profiles,
|
||||
"Path": ctx.RequestPath(false),
|
||||
}
|
||||
|
||||
if err := indexTmpl.Execute(ctx, data); err != nil {
|
||||
ctx.Application().Logger().Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var indexTmpl = template.Must(template.New("index").Parse(`<html>
|
||||
<head>
|
||||
<title>/{{.Path}}</title>
|
||||
</head>
|
||||
<body>
|
||||
{{.Path}}<br>
|
||||
<br>
|
||||
profiles:<br>
|
||||
<table>
|
||||
{{$path := .Path}}
|
||||
{{range .Profiles}}
|
||||
<tr><td align=right>{{.Count}}<td><a href="{{$path}}/{{.Name}}?debug=1">{{.Name}}</a>
|
||||
{{end}}
|
||||
</table>
|
||||
<br>
|
||||
<a href="{{$path}}/goroutine?debug=2">full goroutine stack dump</a><br>
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
|
|
Loading…
Reference in New Issue
Block a user