aboutsummaryrefslogtreecommitdiff
path: root/weed/util/grace/pprof.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/util/grace/pprof.go')
-rw-r--r--weed/util/grace/pprof.go34
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()
+ })
+ }
+
+}