diff options
| author | Chris Lu <chris.lu@gmail.com> | 2014-05-07 10:17:06 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2014-05-07 10:17:06 -0700 |
| commit | 729716ab7a19dc774c9acce84eed491711f3da4d (patch) | |
| tree | 9ee1b71eac6759472a1b94f7260a5736b923dafa /go | |
| parent | 87b98711f79b71760fe95f10cd32f7a0c21bf3d6 (diff) | |
| download | seaweedfs-729716ab7a19dc774c9acce84eed491711f3da4d.tar.xz seaweedfs-729716ab7a19dc774c9acce84eed491711f3da4d.zip | |
Add cpu profiling option.
Diffstat (limited to 'go')
| -rw-r--r-- | go/weed/server.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/go/weed/server.go b/go/weed/server.go index a99ed0423..c4f857dc1 100644 --- a/go/weed/server.go +++ b/go/weed/server.go @@ -7,15 +7,22 @@ import ( "github.com/gorilla/mux" "net/http" "os" + "os/signal" "runtime" + "runtime/pprof" "strconv" "strings" "sync" "time" ) +type ServerOptions struct { + cpuprofile *string +} + var ( - filer FilerOptions + filer FilerOptions + serverOptions ServerOptions ) func init() { @@ -68,9 +75,29 @@ func init() { filer.port = cmdServer.Flag.Int("filer.port", 8888, "filer server http listen port") filer.dir = cmdServer.Flag.String("filer.dir", "", "directory to store meta data, default to a 'filer' sub directory of what -mdir is specified") filer.defaultReplicaPlacement = cmdServer.Flag.String("filer.defaultReplicaPlacement", "", "Default replication type if not specified during runtime.") + serverOptions.cpuprofile = cmdServer.Flag.String("cpuprofile", "", "write cpu profile to file") } func runServer(cmd *Command, args []string) bool { + if *serverOptions.cpuprofile != "" { + f, err := os.Create(*serverOptions.cpuprofile) + if err != nil { + glog.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + + signalChan := make(chan os.Signal, 1) + signal.Notify(signalChan, os.Interrupt) + go func() { + for _ = range signalChan { + // sig is a ^C, handle it + pprof.StopCPUProfile() + os.Exit(0) + } + }() + + } if *serverPublicIp == "" { if *serverIp == "" { |
