非侵入式的分析工具。

go官方库自带,分为两种: 监控终端运行,监控服务运行。

一、采集command-监控终端运行

库为: runtime/pprof

1、收集运行信息

  引入包

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

file, _ := os.Create(*cpuprofile)
func main() {

  pprof.StartCPUProfile(f)
  defer pprof.StopCPUProfile()

  //下面需要尽量复杂的运算过程
} 

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

 

二、采集server-监控服务运行

库为: net/http/pprof

三、分析

  实时服务分析

    通过http监控服务,可以通过额外提供的http服务观察当前对外提供业务服务器性能。

    可以提供基础的监控信息

  监控文件分析

    无论是监控服务运行,还是监控终端运行,都可以生成对应的profile文件。

    文件分析,可以提供流程图、火焰图等分析方法

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

    self profile就是上面main包中新建的文件。

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

 

posted on 2023-03-25 12:04  黑熊一只  阅读(57)  评论(0)    收藏  举报