aboutsummaryrefslogtreecommitdiff
path: root/weed/command
diff options
context:
space:
mode:
Diffstat (limited to 'weed/command')
-rw-r--r--weed/command/master.go15
-rw-r--r--weed/command/mount_std.go2
-rw-r--r--weed/command/server.go2
-rw-r--r--weed/command/signal_handling.go31
-rw-r--r--weed/command/signal_handling_notsupported.go6
-rw-r--r--weed/command/volume.go7
6 files changed, 11 insertions, 52 deletions
diff --git a/weed/command/master.go b/weed/command/master.go
index 09089a4f9..8c5efbb9f 100644
--- a/weed/command/master.go
+++ b/weed/command/master.go
@@ -4,7 +4,6 @@ import (
"net/http"
"os"
"runtime"
- "runtime/pprof"
"strconv"
"strings"
"time"
@@ -48,6 +47,7 @@ var (
masterWhiteListOption = cmdMaster.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
masterSecureKey = cmdMaster.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
masterCpuProfile = cmdMaster.Flag.String("cpuprofile", "", "cpu profile output file")
+ masterMemProfile = cmdMaster.Flag.String("memprofile", "", "memory profile output file")
masterWhiteList []string
)
@@ -57,17 +57,8 @@ func runMaster(cmd *Command, args []string) bool {
*mMaxCpu = runtime.NumCPU()
}
runtime.GOMAXPROCS(*mMaxCpu)
- if *masterCpuProfile != "" {
- f, err := os.Create(*masterCpuProfile)
- if err != nil {
- glog.Fatal(err)
- }
- pprof.StartCPUProfile(f)
- defer pprof.StopCPUProfile()
- OnInterrupt(func() {
- pprof.StopCPUProfile()
- })
- }
+ util.SetupProfiling(*masterCpuProfile, *masterMemProfile)
+
if err := util.TestFolderWritable(*metaFolder); err != nil {
glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *metaFolder, err)
}
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index a87068675..0c36e488f 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -31,7 +31,7 @@ func runMount(cmd *Command, args []string) bool {
return false
}
- OnInterrupt(func() {
+ util.OnInterrupt(func() {
fuse.Unmount(*mountOptions.dir)
c.Close()
})
diff --git a/weed/command/server.go b/weed/command/server.go
index c8878e9eb..cd8ddf66a 100644
--- a/weed/command/server.go
+++ b/weed/command/server.go
@@ -290,7 +290,7 @@ func runServer(cmd *Command, args []string) bool {
}()
}
- OnInterrupt(func() {
+ util.OnInterrupt(func() {
volumeServer.Shutdown()
pprof.StopCPUProfile()
})
diff --git a/weed/command/signal_handling.go b/weed/command/signal_handling.go
deleted file mode 100644
index 182e2754d..000000000
--- a/weed/command/signal_handling.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// +build !plan9
-
-package command
-
-import (
- "os"
- "os/signal"
- "syscall"
-)
-
-func OnInterrupt(fn func()) {
- // deal with control+c,etc
- signalChan := make(chan os.Signal, 1)
- // controlling terminal close, daemon not exit
- signal.Ignore(syscall.SIGHUP)
- signal.Notify(signalChan,
- os.Interrupt,
- os.Kill,
- syscall.SIGALRM,
- // syscall.SIGHUP,
- syscall.SIGINT,
- syscall.SIGTERM,
- // syscall.SIGQUIT,
- )
- go func() {
- for _ = range signalChan {
- fn()
- os.Exit(0)
- }
- }()
-}
diff --git a/weed/command/signal_handling_notsupported.go b/weed/command/signal_handling_notsupported.go
deleted file mode 100644
index dfcc24a3e..000000000
--- a/weed/command/signal_handling_notsupported.go
+++ /dev/null
@@ -1,6 +0,0 @@
-// +build plan9
-
-package command
-
-func OnInterrupt(fn func()) {
-}
diff --git a/weed/command/volume.go b/weed/command/volume.go
index ad9803974..a54ffd1fd 100644
--- a/weed/command/volume.go
+++ b/weed/command/volume.go
@@ -36,6 +36,8 @@ type VolumeServerOptions struct {
indexType *string
fixJpgOrientation *bool
readRedirect *bool
+ cpuProfile *string
+ memProfile *string
}
func init() {
@@ -54,6 +56,8 @@ func init() {
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb|btree] mode for memory~performance balance.")
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
+ v.cpuProfile = cmdVolume.Flag.String("cpuprofile", "", "cpu profile output file")
+ v.memProfile = cmdVolume.Flag.String("memprofile", "", "memory profile output file")
}
var cmdVolume = &Command{
@@ -75,6 +79,7 @@ func runVolume(cmd *Command, args []string) bool {
*v.maxCpu = runtime.NumCPU()
}
runtime.GOMAXPROCS(*v.maxCpu)
+ util.SetupProfiling(*v.cpuProfile, *v.memProfile)
//Set multiple folders and each folder's max volume count limit'
v.folders = strings.Split(*volumeFolders, ",")
@@ -156,7 +161,7 @@ func runVolume(cmd *Command, args []string) bool {
}()
}
- OnInterrupt(func() {
+ util.OnInterrupt(func() {
volumeServer.Shutdown()
})