go-pprof

发布时间 2023-03-25 12:09:48作者: 黑熊一只

非侵入式的分析工具。

主要分为几个阶段。

1、收集运行信息

  引入包

import "runtime/pprof"
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
 

  同时,需要将相关收集到的信息,写入到特定文件。

2、分析

  go tool pprof --http=:8080 ~/self profile

  通过 go tool pprof分析自己采集到的profile文件。