fanchann / pprof

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

golang pprof

with unit test

# generate report with unit test
go test -v -run=TestFunctionName -cpuprofile report/test/cpu.prof -memprofile report/test/mem.prof
# benchmark
go test -bench=BenchName -benchmem -cpuprofile report/cpu.prof -memprofile report/mem.prof -benchtime=5s

without unit test

  • cpucprof
	f, err := os.Create("report/functions/cpu.pprof")
	if err != nil {
		panic(err)
	}
	pprof.StartCPUProfile(f)
	defer f.Close()
	defer pprof.StopCPUProfile()
  • memprof
	f, err := os.Create("report/functions/mem.pprof")
	if err != nil {
		panic(err)
	}
	pprof.WriteHeapProfile(f)
	defer f.Close()
# see the report,
go tool pprof -http=:8080 report/test/mem.prof
  • how to read the pprof report

url

About


Languages

Language:Go 100.0%