robfig/revel — pull request #424 by landr0id (2013-12-22 21:30:07+00:00)
Title: Add pprof module

These commits add a pprof module to the framework for binary profiling (#264). The `net/http/pprof` package is meant to be imported for the side effects (`import _ "net/http/pprof"`), so one thing that I had a concern about is the `init` method, since it calls `http.Handle` for each of its handlers. However, this doesn't seem to affect anything in Revel. Maybe someone else can elaborate on whether or not that causes performance or other unnoticed side affects.

I modified the booking app to load the module (just put `module:pprof` in your routes and add the module in your config), so if you visit `/debug/pprof` or `go tool pprof http://localhost:9000`, you'll be in business.

I did not see any huge reasons to rewrite the code already written by the Go authors. However, reimplementing `pprof` would have the following benefits:

- Control over routes. The `net/http/pprof` package expects to be responding to `/debug/pprof*`, `/pprof/profile`, and `pprof/symbol` routes. The latter two **must** be at that location in order for the command line tool to work (see the example below)
- Control over how the page is displayed (below). Anchors in the page also currently assume that the routes are `/debug/pprof*`.
![screen shot 2013-12-22 at 1 24 06 pm](https://f.cloud.github.com/assets/1313522/1798458/7d2c492c-6b4f-11e3-9585-75b6ed9c4772.png)
![screen shot 2013-12-22 at 1 24 19 pm](https://f.cloud.github.com/assets/1313522/1798459/7d2ec4a4-6b4f-11e3-9f4d-2f5d6c0c4fcb.png)

Here is an example `go tool pprof` command execution:

$ go tool pprof ~/go/bin/ http://localhost:9000
Gathering CPU profile from http://localhost:9000/pprof/profile?seconds=30 for 30 seconds to
/Users/lander/pprof/.1387747238.localhost-port9000
Be patient...
Wrote profile to /Users/lander/pprof/.1387747238.localhost-port9000
Welcome to pprof! For help, type 'help'.
(pprof) [etc]

If you try directing the tool to any other path. For example `go tool pprof ~/go/bin/ http://localhost:9000/pprof/profile/test`, the tool will output: `http://localhost:9000/pprof/profile/test: No such file or directory`