在golang 单元测试中使用pprof做性能分析

Test with pprof

  • git clone xxxxx
  • cd service
  • go test -test.cpuprofile=cpu.out -v
  • go test -test.memprofile=mem.out -v
  • go tool pprof cpu.out (or mem.out)

进入交互界面,可使用top tree等命令查看cpu或memory使用情况

  • go tool pprof -http localhost:9000 cpu.out (or mem.out)

效果图如下(可下拉选择普通图标或者火焰图)