hdkv
/
fwzookeeper
Archived
1
Fork 0
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues/pull-requests.
fwzookeeper/vendor/github.com/kirillDanshin/myutils/cpuprof.go

29 lines
507 B
Go

package myutils
import (
"flag"
"log"
"os"
"runtime/pprof"
)
var cpupprof = flag.String("cpupprof", "", "CPU profile output file path")
// CPUProf runs the profiler and returns a function you need to defer
func CPUProf() func() {
flag.Parse()
out := *cpupprof
if out != "" {
file, err := os.Create(out)
if err != nil {
log.Fatalf("can't open CPU profile file %q", out)
}
pprof.StartCPUProfile(file)
return func() {
pprof.StopCPUProfile()
file.Close()
}
}
return func() {}
}