update
1. change pprof module 2. remove memory log 3. remove line hook log 4. send line log to es
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.5
|
||||
- 1.6
|
||||
- 1.7
|
||||
- 1.8
|
||||
- tip
|
||||
|
||||
script:
|
||||
- go test
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Yangliang Li
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
ginpprof
|
||||
========
|
||||
|
||||
[](https://godoc.org/github.com/DeanThompson/ginpprof)
|
||||
[](https://travis-ci.org/DeanThompson/ginpprof)
|
||||
|
||||
A wrapper for [golang web framework gin](https://github.com/gin-gonic/gin) to use `net/http/pprof` easily.
|
||||
|
||||
## Install
|
||||
|
||||
First install ginpprof to your GOPATH using `go get`:
|
||||
|
||||
```sh
|
||||
go get github.com/DeanThompson/ginpprof
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/DeanThompson/ginpprof"
|
||||
)
|
||||
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
|
||||
router.GET("/ping", func(c *gin.Context) {
|
||||
c.String(200, "pong")
|
||||
})
|
||||
|
||||
// automatically add routers for net/http/pprof
|
||||
// e.g. /debug/pprof, /debug/pprof/heap, etc.
|
||||
ginpprof.Wrap(router)
|
||||
|
||||
// ginpprof also plays well with *gin.RouterGroup
|
||||
// group := router.Group("/debug/pprof")
|
||||
// ginpprof.WrapGroup(group)
|
||||
|
||||
router.Run(":8080")
|
||||
}
|
||||
```
|
||||
|
||||
Start this server, and you will see such outputs:
|
||||
|
||||
```text
|
||||
[GIN-debug] GET /ping --> main.main.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/ --> github.com/DeanThompson/ginpprof.IndexHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/heap --> github.com/DeanThompson/ginpprof.HeapHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/goroutine --> github.com/DeanThompson/ginpprof.GoroutineHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/block --> github.com/DeanThompson/ginpprof.BlockHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/threadcreate --> github.com/DeanThompson/ginpprof.ThreadCreateHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/cmdline --> github.com/DeanThompson/ginpprof.CmdlineHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/profile --> github.com/DeanThompson/ginpprof.ProfileHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
|
||||
[GIN-debug] POST /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/trace --> github.com/DeanThompson/ginpprof.TraceHandler.func1 (3 handlers)
|
||||
[GIN-debug] GET /debug/pprof/mutex --> github.com/DeanThompson/ginpprof.MutexHandler.func1 (3 handlers)
|
||||
[GIN-debug] Listening and serving HTTP on :8080
|
||||
```
|
||||
|
||||
Now visit [http://127.0.0.1:8080/debug/pprof/](http://127.0.0.1:8080/debug/pprof/) and you'll see what you want.
|
||||
|
||||
Have Fun.
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package ginpprof
|
||||
|
||||
import (
|
||||
"net/http/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Wrap adds several routes from package `net/http/pprof` to *gin.Engine object
|
||||
func Wrap(router *gin.Engine) {
|
||||
WrapGroup(&router.RouterGroup)
|
||||
}
|
||||
|
||||
// Wrapper make sure we are backward compatible
|
||||
var Wrapper = Wrap
|
||||
|
||||
// WrapGroup adds several routes from package `net/http/pprof` to *gin.RouterGroup object
|
||||
func WrapGroup(router *gin.RouterGroup) {
|
||||
routers := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/debug/pprof/", IndexHandler()},
|
||||
{"GET", "/debug/pprof/heap", HeapHandler()},
|
||||
{"GET", "/debug/pprof/goroutine", GoroutineHandler()},
|
||||
{"GET", "/debug/pprof/block", BlockHandler()},
|
||||
{"GET", "/debug/pprof/threadcreate", ThreadCreateHandler()},
|
||||
{"GET", "/debug/pprof/cmdline", CmdlineHandler()},
|
||||
{"GET", "/debug/pprof/profile", ProfileHandler()},
|
||||
{"GET", "/debug/pprof/symbol", SymbolHandler()},
|
||||
{"POST", "/debug/pprof/symbol", SymbolHandler()},
|
||||
{"GET", "/debug/pprof/trace", TraceHandler()},
|
||||
{"GET", "/debug/pprof/mutex", MutexHandler()},
|
||||
}
|
||||
|
||||
basePath := strings.TrimSuffix(router.BasePath(), "/")
|
||||
var prefix string
|
||||
|
||||
switch {
|
||||
case basePath == "":
|
||||
prefix = ""
|
||||
case strings.HasSuffix(basePath, "/debug"):
|
||||
prefix = "/debug"
|
||||
case strings.HasSuffix(basePath, "/debug/pprof"):
|
||||
prefix = "/debug/pprof"
|
||||
}
|
||||
|
||||
for _, r := range routers {
|
||||
router.Handle(r.Method, strings.TrimPrefix(r.Path, prefix), r.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
// IndexHandler will pass the call from /debug/pprof to pprof
|
||||
func IndexHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Index(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// HeapHandler will pass the call from /debug/pprof/heap to pprof
|
||||
func HeapHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Handler("heap").ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof
|
||||
func GoroutineHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Handler("goroutine").ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// BlockHandler will pass the call from /debug/pprof/block to pprof
|
||||
func BlockHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Handler("block").ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof
|
||||
func ThreadCreateHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Handler("threadcreate").ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof
|
||||
func CmdlineHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Cmdline(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// ProfileHandler will pass the call from /debug/pprof/profile to pprof
|
||||
func ProfileHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Profile(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// SymbolHandler will pass the call from /debug/pprof/symbol to pprof
|
||||
func SymbolHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Symbol(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// TraceHandler will pass the call from /debug/pprof/trace to pprof
|
||||
func TraceHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Trace(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
|
||||
// MutexHandler will pass the call from /debug/pprof/mutex to pprof
|
||||
func MutexHandler() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
pprof.Handler("mutex").ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user