# 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
f, err := os.Create("report/functions/cpu.pprof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer f.Close()
defer pprof.StopCPUProfile()
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