-
web服務(wù)器
import _"net/http/pprof" go func() { log.Println(http.ListenAndServe("localhost:6666", nil)) }()
-
應(yīng)用程序
import "runtime/pprof" func main() { ... f, err := os.Create("cpu.prof") if err != nil { log.Fatal(err) } defer f.close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile()
go tool pprof XXX cpu.prof
為golang程序使用pprof遠程查看httpserver運行堆棧,cpu耗時等信息
go tool pprof http://localhost:6666/debug/pprof/profile
使用go tool pprof分析內(nèi)存泄漏、CPU消耗
fm, err := os.Create("mem.prof")
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(fm)
fm.Close()
13.10 性能調(diào)試:分析并優(yōu)化 Go 程序
func saveHeapProfile() {
runtime.GC()
f, err := os.Create(fmt.Sprintf("prof/heap_%s_%d_%s.prof", progname, pid, time.Now().Format("2006_01_02_03_04_05")))
if err != nil {
return
}
defer f.Close()
pprof.Lookup("heap").WriteTo(f, 1)
}
保存堆信息之前先GC了一下,以進行垃圾回收,之后保存下來的堆信息將更精確地告訴我們哪些地方可能會造成內(nèi)存泄露,無法被垃圾回收的传于。
[golang]內(nèi)存不斷增長bytes.makeSlice
Golang使用pprof監(jiān)控性能及GC調(diào)優(yōu)
提及 pkg/profile 包
Debugging performance issues in Go programs
Golang Slices And The Case Of The Missing Memory
golang profiling -- Yandong Yao
graphviz
官網(wǎng):
http://www.graphviz.org/Download..php
SuSE:
http://download.opensuse.org/repositories/graphics/SLE_12/x86_64/graphviz-2.38.0-137.1.x86_64.rpm