go-pprof工具使用简介

 

1.在程序import 中增加

_ "net/http/pprof"

2.程序中增加

go func() {

        log.Println(http.ListenAndServe("localhost:6060", nil))

    }()

3.运行程序

go run main.go

4.另启动terminal,运行

go tool pprof --text http://localhost:6060/debug/pprof/profile ,如下:

$ go tool pprof --text http://localhost:6060/debug/pprof/profile

Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile

Saved profile in C:\Users\Administrator.WIN7-1609091712\pprof\pprof.samples.cpu.004.pb.gz

Type: cpu

Time: Jun 23, 2020 at 2:59pm (CST)

Duration: 30.17s, Total samples = 13.79s (45.71%)

Showing nodes accounting for 13.53s, 98.11% of 13.79s total

Dropped 84 nodes (cum <= 0.07s)

      flat  flat%   sum%        cum   cum%

    13.52s 98.04% 98.04%     13.53s 98.11%  runtime.cgocall

     0.01s 0.073% 98.11%     13.56s 98.33%  github.com/goburrow/modbus.(*client).ReadHoldingRegisters

         0     0% 98.11%     13.55s 98.26%  github.com/goburrow/modbus.(*client).send

         0     0% 98.11%     13.55s 98.26%  github.com/goburrow/modbus.(*rtuSerialTransporter).Send

         0     0% 98.11%     13.46s 97.61%  github.com/goburrow/serial.(*port).Read

         0     0% 98.11%     13.46s 97.61%  io.ReadAtLeast

         0     0% 98.11%     13.45s 97.53%  syscall.ReadFile

         0     0% 98.11%     13.52s 98.04%  syscall.Syscall6

         0     0% 98.11%     13.58s 98.48%  xxnet/modstation.(*Channel).getTemp

         0     0% 98.11%     13.56s 98.33%  xxnet/modstation.(*Channel).readTemperature

         0     0% 98.11%     13.59s 98.55%  xxnet/modstation.(*Channel).requestData

         0     0% 98.11%     13.62s 98.77%  xxnet/modstation.(*ChannelManager).RequestData.func1

         0     0% 98.11%      0.07s  0.51%  xxnet/modstation.(*ChannelManager).writePointThread

5.运行

go tool pprof -http=:8080 "C:\Users\Administrator.WIN7-1609091712\pprof\pprof.samples.cpu.004.pb.gz"

Serving web UI on http://localhost:8080

弹出界面

http://localhost:8080/ui/?si=cpu

以上只是使用方法,没做深入的使用分析。是个好工具!

posted @ 2020-06-23 15:16  探索无止境  阅读(1130)  评论(0编辑  收藏  举报