go - How to profile benchmarks using the pprof tool? -
i want profile benchmarks generated go test -c
, go tool pprof
needs profile file generated inside main function this:
func main() { flag.parse() if *cpuprofile != "" { f, err := os.create(*cpuprofile) if err != nil { log.fatal(err) } pprof.startcpuprofile(f) defer pprof.stopcpuprofile() }
how can create profile file within benchmarks ?
as described in http://golang.org/cmd/go/#hdr-description_of_testing_flags can specify profile file using flag -cpuprofile
.
for example
go test -cpuprofile cpu.out
Comments
Post a Comment