From 1ddc91f0eab696142eac131af91172b374a621d4 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 14 Jul 2016 13:34:20 +0100 Subject: [PATCH 1/3] Add flag for block profiling Fixes #1672 Test by adding `--app.block.profile.rate=1`, running scope in multi-tenant mode and browsing to http:///debug/pprof/ --- prog/app.go | 2 ++ prog/main.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/prog/app.go b/prog/app.go index 0642676e8..b63ace7a3 100644 --- a/prog/app.go +++ b/prog/app.go @@ -7,6 +7,7 @@ import ( _ "net/http/pprof" "net/url" "os" + "runtime" "strconv" "strings" "time" @@ -199,6 +200,7 @@ func pipeRouterFactory(userIDer multitenant.UserIDer, pipeRouterURL, consulInf s func appMain(flags appFlags) { setLogLevel(flags.logLevel) setLogFormatter(flags.logPrefix) + runtime.SetBlockProfileRate(flags.blockProfileRate) defer log.Info("app exiting") rand.Seed(time.Now().UnixNano()) diff --git a/prog/main.go b/prog/main.go index 7e9aed1f6..44b99e060 100644 --- a/prog/main.go +++ b/prog/main.go @@ -111,6 +111,8 @@ type appFlags struct { memcachedExpiration time.Duration userIDHeader string + blockProfileRate int + awsCreateTables bool consulInf string } @@ -197,6 +199,8 @@ func main() { flag.StringVar(&flags.app.memcachedService, "app.memcached.service", "memcached", "SRV service used to discover memcache servers.") flag.StringVar(&flags.app.userIDHeader, "app.userid.header", "", "HTTP header to use as userid") + flag.IntVar(&flags.app.blockProfileRate, "app.block.profile.rate", 0, "If more than 0, enable block profiling. The profiler aims to sample an average of one blocking event per rate nanoseconds spent blocked.") + flag.BoolVar(&flags.app.awsCreateTables, "app.aws.create.tables", false, "Create the tables in DynamoDB") flag.StringVar(&flags.app.consulInf, "app.consul.inf", "", "The interface who's address I should advertise myself under in consul") From 7894442ee7d1f55538f315852a5f45c542948d4c Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 14 Jul 2016 15:17:56 +0100 Subject: [PATCH 2/3] Update site/building.md with profiling docs --- site/building.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/site/building.md b/site/building.md index 5f24fdf0d..dcfc21891 100644 --- a/site/building.md +++ b/site/building.md @@ -72,6 +72,12 @@ To collect the CPU profile of the Scope Probe: go tool pprof http://localhost:4041/debug/pprof/profile +To collect a blocking profile of the Scope App, make sure you have launched +Scope with `--app.block.profile.rate=N` (where `N` is the number of +nanoseconds between samples) and then: + + go tool pprof http://localhost:4040/debug/pprof/ + If you don't have `go` installed, you can use a Docker container instead: To collect the memory profile of the Scope App: From 0edd2e7bf960189dad6a7ebc2f675987c704ece6 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 14 Jul 2016 15:26:34 +0100 Subject: [PATCH 3/3] Oops --- site/building.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/building.md b/site/building.md index dcfc21891..70ce93bcc 100644 --- a/site/building.md +++ b/site/building.md @@ -76,7 +76,7 @@ To collect a blocking profile of the Scope App, make sure you have launched Scope with `--app.block.profile.rate=N` (where `N` is the number of nanoseconds between samples) and then: - go tool pprof http://localhost:4040/debug/pprof/ + go tool pprof http://localhost:4040/debug/pprof/block If you don't have `go` installed, you can use a Docker container instead: