天天看點

golang之pprof

通過互動式終端使用:

  1. go tool pprof -seconds 30 http://127.0.0.1:9003/debug/pprof/profile
$ go tool pprof -seconds 30 http://127.0.0.1:9003/debug/pprof/profile
Fetching profile over HTTP from http://127.0.0.1:9003/debug/pprof/profile?seconds=30
Please wait... (30s)
Saved profile in C:\Users\Administrator\pprof\pprof.samples.cpu.003.pb.gz
Type: cpu
Time: Jul 8, 2021 at 9:50am (CST)
Duration: 30.08s, Total samples = 1.79s ( 5.95%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) web
(pprof) top 10
Showing nodes accounting for 1270ms, 70.95% of 1790ms total
Showing top 10 nodes out of 232
     flat  flat%   sum%        cum   cum%
    580ms 32.40% 32.40%      580ms 32.40%  runtime.cgocall
    150ms  8.38% 40.78%      160ms  8.94%  runtime.stdcall6
     90ms  5.03% 45.81%       90ms  5.03%  runtime.memmove
     90ms  5.03% 50.84%       90ms  5.03%  runtime.stdcall1
     80ms  4.47% 55.31%       80ms  4.47%  runtime.procyield
     80ms  4.47% 59.78%      150ms  8.38%  runtime.selectgo
     70ms  3.91% 63.69%       70ms  3.91%  runtime.memclrNoHeapPointers
     60ms  3.35% 67.04%      370ms 20.67%  runtime.findrunnable
     40ms  2.23% 69.27%      560ms 31.28%  runtime.mcall
     30ms  1.68% 70.95%      210ms 11.73%  github.com/suiyunonghen/DxCommonLib.
           
  1. go tool pprof -inuse_space -seconds 30 http://127.0.0.1:8080/debug/pprof/heap指令連接配接到程序中 檢視正在使用的一些記憶體相關資訊,此時我們得到一個可以互動的指令行
$ go tool pprof -inuse_space http://127.0.0.1:9003/debug/pprof/heap
Fetching profile over HTTP from http://127.0.0.1:9003/debug/pprof/heap
Saved profile in C:\Users\Administrator\pprof\pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.005.pb.gz
Type: inuse_space
Time: Jul 7, 2021 at 3:10pm (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top 5
Showing nodes accounting for 9129.86kB, 89.91% of 10154.02kB total
Showing top 5 nodes out of 57
      flat  flat%   sum%        cum   cum%
 6778.88kB 66.76% 66.76%  6778.88kB 66.76%  golang.org/x/net/webdav.(*memFile).Write
  809.97kB  7.98% 74.74%   809.97kB  7.98%  bytes.makeSlice
  514.38kB  5.07% 79.80%   514.38kB  5.07%  github.com/360EntSecGroup-Skylar/excelize/v2.init
  513.31kB  5.06% 84.86%   513.31kB  5.06%  regexp.makeOnePass.func1
  513.31kB  5.06% 89.91%   513.31kB  5.06%  regexp/syntax.(*compiler).inst
(pprof)
           
  1. go tool pprof -alloc_space -seconds 30 http://127.0.0.1:8080/debug/pprof/heap指令連結程式來檢視 記憶體對象配置設定的相關情況。然後輸入top來檢視累積配置設定記憶體較多的一些函數調用:
$ go tool pprof -alloc_space http://127.0.0.1:9003/debug/pprof/heap
Fetching profile over HTTP from http://127.0.0.1:9003/debug/pprof/heap
Saved profile in C:\Users\Administrator\pprof\pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.007.pb.gz
Type: alloc_space
Time: Jul 7, 2021 at 3:25pm (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top 3
Showing nodes accounting for 10021.73MB, 99.28% of 10094.23MB total
Dropped 215 nodes (cum <= 50.47MB)
Showing top 3 nodes out of 40
      flat  flat%   sum%        cum   cum%
 5528.48MB 54.77% 54.77%  5528.48MB 54.77%  io.ReadAll
 3595.60MB 35.62% 90.39%  3595.60MB 35.62%  github.com/minio/minio-go/v7.Client.putObjectMultipartStreamFromReadAt
  897.65MB  8.89% 99.28%   897.65MB  8.89%  bytes.makeSlice
(pprof)