4 种类型

  • CPU profiling:函数/方法执行耗时
  • Memory profiling:内存占用情况
  • Block profiling:记录 goroutine 在等待共享资源花费的时间
  • Mutex profiling:记录因为锁竞争导致的等待或延迟

采样方式

  • runtime/pprof:采集程序(非 Server)的指定区块的运行数据进行分析
  • net/http/pprof:基于 HTTP Server 运行,并且可以采集运行时数据进行分析
  • go test:通过运行测试用例,并指定所需标识来进行采集
/debug/pprof/goroutine?debug=2
debug=1页面的展示信息可读性较差
/debug/pprof/goroutine?debug=2
可以看出每个goroutine的调用堆栈,持续时间,属于何种操作(chan send/chan receive/select/IO wait/…)