diff options
| author | wuyuxiang <wuyuxiang@corp.netease.com> | 2020-04-28 14:10:23 +0800 |
|---|---|---|
| committer | wuyuxiang <wuyuxiang@corp.netease.com> | 2020-04-28 14:10:23 +0800 |
| commit | 6850d28d6b99155dca2da8fa8bbf76124f528fa4 (patch) | |
| tree | 2a6eb0dd50a530dfb72496a69715438c9aa15a44 /weed/util/grace/pprof.go | |
| parent | 2a7957b4ca83fdb5232d761074e81dce6b99648f (diff) | |
| download | seaweedfs-6850d28d6b99155dca2da8fa8bbf76124f528fa4.tar.xz seaweedfs-6850d28d6b99155dca2da8fa8bbf76124f528fa4.zip | |
refacotr: move signal handling and pprof to grace package
Diffstat (limited to 'weed/util/grace/pprof.go')
| -rw-r--r-- | weed/util/grace/pprof.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/weed/util/grace/pprof.go b/weed/util/grace/pprof.go new file mode 100644 index 000000000..14686bfc8 --- /dev/null +++ b/weed/util/grace/pprof.go @@ -0,0 +1,34 @@ +package grace + +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() + }) + } + +} |
