From 9fdff7b15002a727b7e7539f8e23da1f21691f93 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Thu, 14 Dec 2017 15:34:05 -0500 Subject: [PATCH] Add the global -profile option to enable profiling --- duplicacy/duplicacy_main.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/duplicacy/duplicacy_main.go b/duplicacy/duplicacy_main.go index b654091..efb4dbf 100644 --- a/duplicacy/duplicacy_main.go +++ b/duplicacy/duplicacy_main.go @@ -16,6 +16,9 @@ import ( "runtime" "strconv" "strings" + "net/http" + + _ "net/http/pprof" "github.com/gilbertchen/cli" @@ -138,6 +141,15 @@ func setGlobalOptions(context *cli.Context) { ScriptEnabled = false } + address := context.GlobalString("profile") + if address != "" { + go func() { + http.ListenAndServe(address, nil) + }() + } + + + duplicacy.RunInBackground = context.GlobalBool("background") } @@ -1302,7 +1314,7 @@ func main() { }, cli.BoolFlag{ Name: "dry-run", - Usage: "Dry run for testing, don't backup anything. Use with -stats and -d", + Usage: "dry run for testing, don't backup anything. Use with -stats and -d", }, cli.BoolFlag{ Name: "vss", @@ -1811,7 +1823,13 @@ func main() { Name: "background", Usage: "read passwords, tokens, or keys only from keychain/keyring or env", }, - } + cli.StringFlag{ + Name: "profile", + Value: "", + Usage: "enable the profiling tool and listen on the specified address:port", + Argument: "", + }, +} app.HideVersion = true app.Name = "duplicacy"