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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM