Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

router: enable pprof handler via build flag #909

Merged
merged 3 commits into from
Jan 31, 2015

Conversation

benburkert
Copy link
Contributor

Profiling the router with the net/http/pprof handler is useful for debugging the router, but it has a lot of baggage. Pulling in the runtime/pprof dependency should not be done by default. This adds a pkg/pprof package that only pulls in the runtime/pprof/net/http/pprof packages when the pprof build tag is set (go build -tags=pprof).

@@ -72,6 +73,7 @@ func main() {
certFile := flag.String("tlscert", "", "TLS (SSL) cert file in pem format")
keyFile := flag.String("tlskey", "", "TLS (SSL) key file in pem format")
apiAddr := flag.String("apiaddr", ":"+apiPort, "api listen address")
pprofAddr := flag.String("pprofaddr", ":6060", "pprof handler listen address")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about mounting this on the API HTTP server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. 👍

@benburkert benburkert force-pushed the router-pprof branch 4 times, most recently from 15337a2 to 62b8f17 Compare January 31, 2015 00:58
@benburkert
Copy link
Contributor Author

ok, the pprof handler is now mounted on the API listener instead of staring it's own listener.


var Handler = http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(404)
rw.Write([]byte(`pprof disabled, go build with -tags=pprof to enable\n`))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \n will be two literal bytes

Only pull in the real net/http/pprof package when the pprof build tag is
set.

Signed-off-by: Ben Burkert <ben@benburkert.com>
Adds the pprof handler to the api listener when built with the pprof
build tag.

Signed-off-by: Ben Burkert <ben@benburkert.com>
Set go build tags via the GO_BUILD_TAGS environment variable.

Signed-off-by: Ben Burkert <ben@benburkert.com>
@benburkert
Copy link
Contributor Author

turns out pprof only prints the status code on a bad URL, so the message body wasn't useful anyways.

@titanous
Copy link
Contributor

LGTM

titanous added a commit that referenced this pull request Jan 31, 2015
router: enable pprof handler via build flag
@titanous titanous merged commit 679d3f5 into flynn:master Jan 31, 2015
@benburkert benburkert deleted the router-pprof branch January 31, 2015 01:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants