1)引用库
"github.com/gin-contrib/pprof"
2)代码
package main
import (
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
app := gin.Default()
// 性能
pprof.Register(app)
app.GET("/test", func(c *gin.Context) {
c.String(http.StatusOK, "test")
})
app.Run(":3000")
}
3)使用
a)直接访问: https://localhost:3000/debug/pprof
b)使用命令行: go tool pprof --seconds 20 https://localhost:3000/debug/pprof/goroutine 然后进入命令行交互
web: 使用web方式打开
top: top耗时函数
list: list 函数名,查看具体函数
pdf:
help: