Gin Web 框架集成 net/http/pprof

DeanThompson · 2015-04-01 07:01:41 · 10377 次点击    
这是一个分享于 2015-04-01 07:01:41 的资源,其中的信息可能已经有所发展或是发生改变。

项目地址: https://github.com/DeanThompson/ginpprof


ginpprof

A wrapper for golang web framework gin to use net/http/pprof easily.

Install

First install ginpprof to your GOPATH using go get:

go get github.com/DeanThompson/ginpprof

Usage

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.Wrapper(router)

    router.Run(":8080")
}

Start this server, and you will see such outputs:

[GIN-debug] GET   /ping                     --> main.func·001 (3 handlers)
[GIN-debug] GET   /debug/pprof/             --> github.com/DeanThompson/ginpprof.func·001 (3 handlers)
[GIN-debug] GET   /debug/pprof/heap         --> github.com/DeanThompson/ginpprof.func·002 (3 handlers)
[GIN-debug] GET   /debug/pprof/goroutine    --> github.com/DeanThompson/ginpprof.func·003 (3 handlers)
[GIN-debug] GET   /debug/pprof/block        --> github.com/DeanThompson/ginpprof.func·004 (3 handlers)
[GIN-debug] GET   /debug/pprof/threadcreate --> github.com/DeanThompson/ginpprof.func·005 (3 handlers)
[GIN-debug] GET   /debug/pprof/cmdline      --> github.com/DeanThompson/ginpprof.func·006 (3 handlers)
[GIN-debug] GET   /debug/pprof/profile      --> github.com/DeanThompson/ginpprof.func·007 (3 handlers)
[GIN-debug] GET   /debug/pprof/symbol       --> github.com/DeanThompson/ginpprof.func·008 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080

Now visit http://127.0.0.1:8080/debug/pprof/ and you'll see what you want.

Have Fun.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

10377 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传