服务型代码 使用pprof性能分析

  • 在main.go 修改为:

package main

import (

"net/http"

_ "net/http/pprof"

"xxxxxxx"

)

func main() {

    go func() {

    http.ListenAndServe("0.0.0.0:8081", nil)

    }()

    xxxxx.Run()

}
  • 在线查看本http服务的文件:

http://localhost:8081/debug/pprof/

文件说明:

/debug/pprof/profile:访问这个链接会自动进行 CPU profiling,持续 30s,并生成一个文件供下载

/debug/pprof/allocs: 分配的内存统计

/debug/pprof/heap: Memory Profiling 的路径,访问这个链接会得到一个内存 Profiling 结果的文件

/debug/pprof/block:block Profiling 的路径

/debug/pprof/goroutines:运行的 goroutines 列表,以及调用关系

  • 查看web界面:

go tool pprof http://127.0.0.1:8081/debug/pprof/heap

pprof: web

go tool pprof http://127.0.0.1:8081/debug/pprof/goroutine

pprof: web

猜你喜欢

转载自blog.csdn.net/Horsdy123/article/details/120172759
今日推荐