You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
543 B
34 lines
543 B
package util
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"runtime/pprof"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
)
|
|
|
|
func SetupProfiling(cpuProfile, memProfile string) {
|
|
if cpuProfile != "" {
|
|
f, err := os.Create(cpuProfile)
|
|
if err != nil {
|
|
glog.Fatal(err)
|
|
}
|
|
pprof.StartCPUProfile(f)
|
|
OnInterrupt(func() {
|
|
pprof.StopCPUProfile()
|
|
})
|
|
}
|
|
if memProfile != "" {
|
|
runtime.MemProfileRate = 1
|
|
f, err := os.Create(memProfile)
|
|
if err != nil {
|
|
glog.Fatal(err)
|
|
}
|
|
OnInterrupt(func() {
|
|
pprof.WriteHeapProfile(f)
|
|
f.Close()
|
|
})
|
|
}
|
|
|
|
}
|