Skip to content

Commit

Permalink
feat(worker): add profiling support
Browse files Browse the repository at this point in the history
Signed-off-by: bigeagle <[email protected]>
  • Loading branch information
bigeagle committed Jun 2, 2016
1 parent f6d53c1 commit 16c49b8
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/tunasync/tunasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/codegangsta/cli"
"github.com/gin-gonic/gin"
"github.com/pkg/profile"
"gopkg.in/op/go-logging.v1"

tunasync "github.com/tuna/tunasync/internal"
Expand Down Expand Up @@ -57,6 +58,20 @@ func startWorker(c *cli.Context) {
os.Exit(1)
}

if profPath := c.String("prof-path"); profPath != "" {
valid := false
if fi, err := os.Stat(profPath); err == nil {
if fi.IsDir() {
valid = true
defer profile.Start(profile.ProfilePath(profPath)).Stop()
}
}
if !valid {
logger.Errorf("Invalid profiling path: %s", profPath)
os.Exit(1)
}
}

go func() {
time.Sleep(1 * time.Second)
sigChan := make(chan os.Signal, 1)
Expand Down Expand Up @@ -98,7 +113,6 @@ func main() {
Name: "config, c",
Usage: "Load manager configurations from `FILE`",
},

cli.StringFlag{
Name: "addr",
Usage: "The manager will listen on `ADDR`",
Expand Down Expand Up @@ -127,7 +141,6 @@ func main() {
Name: "db-type",
Usage: "Use database type `TYPE`",
},

cli.BoolFlag{
Name: "verbose, v",
Usage: "Enable verbose logging",
Expand All @@ -140,7 +153,6 @@ func main() {
Name: "with-systemd",
Usage: "Enable systemd-compatible logging",
},

cli.StringFlag{
Name: "pidfile",
Value: "/run/tunasync/tunasync.manager.pid",
Expand All @@ -158,7 +170,6 @@ func main() {
Name: "config, c",
Usage: "Load worker configurations from `FILE`",
},

cli.BoolFlag{
Name: "verbose, v",
Usage: "Enable verbose logging",
Expand All @@ -171,12 +182,16 @@ func main() {
Name: "with-systemd",
Usage: "Enable systemd-compatible logging",
},

cli.StringFlag{
Name: "pidfile",
Value: "/run/tunasync/tunasync.worker.pid",
Usage: "The pid file of the worker process",
},
cli.StringFlag{
Name: "prof-path",
Value: "",
Usage: "Go profiling file path",
},
},
},
}
Expand Down

0 comments on commit 16c49b8

Please sign in to comment.