pprof进行golang程序性能分析

一、导入包

import _ "net/http/pprof"

二、启动监控routine

go func() {
http.ListenAndServe("0.0.0.0:18080", nil)
}()


三、访问web服务
例:分析CPU占用情况
go tool pprof http://localhost:18080/debug/pprof/profile
(pprof) top10
Total: 2525 samples
     298  11.8%  11.8%      345  13.7% runtime.mapaccess1_fast64
     268  10.6%  22.4%     2124  84.1% main.FindLoops
     251   9.9%  32.4%      451  17.9% scanblock
     178   7.0%  39.4%      351  13.9% hash_insert
     131   5.2%  44.6%      158   6.3% sweepspan
     119   4.7%  49.3%      350  13.9% main.DFS
      96   3.8%  53.1%       98   3.9% flushptrbuf
      95   3.8%  56.9%       95   3.8% runtime.aeshash64
      95   3.8%  60.6%      101   4.0% runtime.settype_flush
      88   3.5%  64.1%      988  39.1% runtime.mallocgc

四、参考
// pprof 命令
https://blog.golang.org/profiling-go-programs
// web 上几项监控指标
https://golang.org/pkg/net/http/pprof/
原文地址:https://www.cnblogs.com/gm-201705/p/8084677.html