golang pprof

golang 性能调试

pprof

cpu:

抓取:

go tool pprof http://ip:admin_port/debug/pprof/profile -seconds 10

查看:

go tool pprof -http=0.0.0.0:8082 /root/pprof/pprof.server.samples.cpu.001.pb.gz

内存:

内存使用:

抓取:

go tool pprof -inuse_space http://ip:admin_port/debug/pprof/heap

直接查看:

go tool pprof /root/pprof/pprof.server.alloc_objects.alloc_space.inuse_objects.inuse_space.001.pb.gz

查看命令

    callgrind        Outputs a graph in callgrind format
    comments         Output all profile comments
    disasm           Output assembly listings annotated with samples
    dot              Outputs a graph in DOT format
    eog              Visualize graph through eog
    evince           Visualize graph through evince
    gif              Outputs a graph image in GIF format
    gv               Visualize graph through gv
    kcachegrind      Visualize report in KCachegrind
    list             Output annotated source for functions matching regexp
    pdf              Outputs a graph in PDF format
    peek             Output callers/callees of functions matching regexp
    png              Outputs a graph image in PNG format
    proto            Outputs the profile in compressed protobuf format
    ps               Outputs a graph in PS format
    raw              Outputs a text representation of the raw profile
    svg              Outputs a graph in SVG format
    tags             Outputs all tags in the profile
    text             Outputs top entries in text form
    top              Outputs top entries in text form
    topproto         Outputs top entries in compressed protobuf format
    traces           Outputs all profile samples in text form
    tree             Outputs a text rendering of call graph
    web              Visualize graph through web browser
    weblist          Display annotated source in a web browser
    o/options        List options and their current values
    quit/exit/^D     Exit pprof

对比查看: 抓取命令执行两次,以下命令可以对比两个时间段的内存分配情况

go tool pprof -base /root/pprof/pprof.server.alloc_objects.alloc_space.inuse_objects.inuse_space.001.pb.gz /root/pprof/pprof.server.alloc_objects.alloc_space.inuse_objects.inuse_space.002.pb.gz

堆栈分配:

wget http://11.185.69.61:11055/debug/pprof/heap?debug=1

协程

抓取: debug=1抓下来的文件可以看到当前goroutine的数量 debug=2抓下来的文件可以看到当前goroutine的详情

wget http://ip:admin_port/debug/pprof/goroutine?debug=1
wget http://ip:admin_port/debug/pprof/goroutine?debug=2
支付宝打赏 微信打赏

您的打赏是对我最大的鼓励!

Table of Contents