mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
feat(worker): add profiling support
Signed-off-by: bigeagle <justin.w.xd@gmail.com>
This commit is contained in:
parent
f6d53c16d6
commit
16c49b8083
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/pkg/profile"
|
||||||
"gopkg.in/op/go-logging.v1"
|
"gopkg.in/op/go-logging.v1"
|
||||||
|
|
||||||
tunasync "github.com/tuna/tunasync/internal"
|
tunasync "github.com/tuna/tunasync/internal"
|
||||||
@ -57,6 +58,20 @@ func startWorker(c *cli.Context) {
|
|||||||
os.Exit(1)
|
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() {
|
go func() {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigChan := make(chan os.Signal, 1)
|
||||||
@ -98,7 +113,6 @@ func main() {
|
|||||||
Name: "config, c",
|
Name: "config, c",
|
||||||
Usage: "Load manager configurations from `FILE`",
|
Usage: "Load manager configurations from `FILE`",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "addr",
|
Name: "addr",
|
||||||
Usage: "The manager will listen on `ADDR`",
|
Usage: "The manager will listen on `ADDR`",
|
||||||
@ -127,7 +141,6 @@ func main() {
|
|||||||
Name: "db-type",
|
Name: "db-type",
|
||||||
Usage: "Use database type `TYPE`",
|
Usage: "Use database type `TYPE`",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "verbose, v",
|
Name: "verbose, v",
|
||||||
Usage: "Enable verbose logging",
|
Usage: "Enable verbose logging",
|
||||||
@ -140,7 +153,6 @@ func main() {
|
|||||||
Name: "with-systemd",
|
Name: "with-systemd",
|
||||||
Usage: "Enable systemd-compatible logging",
|
Usage: "Enable systemd-compatible logging",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "pidfile",
|
Name: "pidfile",
|
||||||
Value: "/run/tunasync/tunasync.manager.pid",
|
Value: "/run/tunasync/tunasync.manager.pid",
|
||||||
@ -158,7 +170,6 @@ func main() {
|
|||||||
Name: "config, c",
|
Name: "config, c",
|
||||||
Usage: "Load worker configurations from `FILE`",
|
Usage: "Load worker configurations from `FILE`",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "verbose, v",
|
Name: "verbose, v",
|
||||||
Usage: "Enable verbose logging",
|
Usage: "Enable verbose logging",
|
||||||
@ -171,12 +182,16 @@ func main() {
|
|||||||
Name: "with-systemd",
|
Name: "with-systemd",
|
||||||
Usage: "Enable systemd-compatible logging",
|
Usage: "Enable systemd-compatible logging",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "pidfile",
|
Name: "pidfile",
|
||||||
Value: "/run/tunasync/tunasync.worker.pid",
|
Value: "/run/tunasync/tunasync.worker.pid",
|
||||||
Usage: "The pid file of the worker process",
|
Usage: "The pid file of the worker process",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "prof-path",
|
||||||
|
Value: "",
|
||||||
|
Usage: "Go profiling file path",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user