14. Go tool pprof
(pprof) web
• svg形式で吐き出されたプロファイルをwebブラウザで表⽰
• function名の指定で絞り込み
• graphvizのインストールが必要
$ go tool pprof mpeg-probe sample.prof/cpu.pprof
Entering interactive mode (type "help" for commands)
(pprof) web main
15. Go tool pprof
(pprof) top
• 取得したプロファイルの上位N件の表⽰
• `-FIELD` 指定によりソート
(pprof) top 5 -flat
100.14s of 112.28s total (89.19%)
Dropped 148 nodes (cum <= 0.56s)
Showing top 5 nodes out of 92 (cum >= 3.02s)
flat flat% sum% cum cum%
78.03s 69.50% 69.50% 78.18s 69.63% syscall.Syscall
8.47s 7.54% 77.04% 8.47s 7.54% runtime.mach_semaphore_wait
7.19s 6.40% 83.44% 7.19s 6.40% runtime.mach_semaphore_signal
3.43s 3.05% 86.50% 3.43s 3.05% runtime.mach_semaphore_timedwait
3.02s 2.69% 89.19% 3.02s 2.69% runtime.memclrNoHeapPointers
flat : 関数の使⽤した値
flat% : flat値の全体の占める割合
sum% : 現在のソート順でのflat値の累計値
cum : 関数の他の関数の呼び出しも含めた値
cum% : cum値の全体に占める割合
16. Go tool pprof
(pprof) list
• go tool実⾏時にバイナリファイルの指定が必要
• ソースコード上でのflat,cum値を表⽰
(pprof) list io.Copy
Total: 1.87mins
ROUTINE ======================== io.Copy in /usr/local/Cellar/go/1.8.1/libexec/src/io/io.go
0 1.09mins (flat, cum) 58.15% of Total
. . 355:// If src implements the WriterTo interface,
. . 356:// the copy is implemented by calling src.WriteTo(dst).
. . 357:// Otherwise, if dst implements the ReaderFrom interface,
. . 358:// the copy is implemented by calling dst.ReadFrom(src).
. . 359:func Copy(dst Writer, src Reader) (written int64, err error) {
. 1.09mins 360: return copyBuffer(dst, src, nil)
. . 361:}
. . 362:
. . 363:// CopyBuffer is identical to Copy except that it stages through the
. . 364:// provided buffer (if one is required) rather than allocating a