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

29 lines
507 B
Go
Raw Normal View History

2018-12-22 17:38:56 +04:00
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() {}
}