Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: common/runtime/profiling/profiler.go

Issue 2588643002: Enable AppEngine profiling endpoints. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« appengine/gaemiddleware/routes.go ('K') | « appengine/gaemiddleware/routes.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/runtime/profiling/profiler.go
diff --git a/common/runtime/profiling/profiler.go b/common/runtime/profiling/profiler.go
index e599c84a033728667dbf437b8ff28e943c2c3f8f..891b642a9f013a431986f23a6c7f115460161100 100644
--- a/common/runtime/profiling/profiler.go
+++ b/common/runtime/profiling/profiler.go
@@ -16,7 +16,8 @@ import (
"runtime/pprof"
"sync/atomic"
- "github.com/julienschmidt/httprouter"
+ "github.com/luci/luci-go/server/router"
+
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/errors"
"github.com/luci/luci-go/common/logging"
@@ -71,17 +72,8 @@ func (p *Profiler) Start() error {
}
func (p *Profiler) startHTTP() error {
- // Register paths: https://golang.org/src/net/http/pprof/pprof.go
- router := httprouter.New()
- router.HandlerFunc("GET", "/debug/pprof/", httpProf.Index)
- router.HandlerFunc("GET", "/debug/pprof/cmdline", httpProf.Cmdline)
- router.HandlerFunc("GET", "/debug/pprof/profile", httpProf.Profile)
- router.HandlerFunc("GET", "/debug/pprof/symbol", httpProf.Symbol)
- router.HandlerFunc("GET", "/debug/pprof/trace", httpProf.Trace)
- for _, p := range pprof.Profiles() {
- name := p.Name()
- router.Handler("GET", fmt.Sprintf("/debug/pprof/%s", name), httpProf.Handler(name))
- }
+ r := router.New()
+ InstallHandlers(r, router.MiddlewareChain{})
// Bind to our profiling port.
l, err := net.Listen("tcp4", p.BindHTTP)
@@ -91,7 +83,7 @@ func (p *Profiler) startHTTP() error {
}
server := http.Server{
- Handler: http.HandlerFunc(router.ServeHTTP),
+ Handler: http.HandlerFunc(r.ServeHTTP),
}
go func() {
if err := server.Serve(l); err != nil {
@@ -158,3 +150,30 @@ func (p *Profiler) getLogger() logging.Logger {
}
return logging.Null
}
+
+// InstallHandlers installs standard profiler paths into the supplied Router.
+//
+// See https://golang.org/src/net/http/pprof/pprof.go
+func InstallHandlers(r *router.Router, base router.MiddlewareChain) {
+ r.GET("/debug/pprof/", base, wrapHandlerFunc(httpProf.Index))
+ r.GET("/debug/pprof/cmdline", base, wrapHandlerFunc(httpProf.Cmdline))
+ r.GET("/debug/pprof/profile", base, wrapHandlerFunc(httpProf.Profile))
+ r.GET("/debug/pprof/symbol", base, wrapHandlerFunc(httpProf.Symbol))
+ r.GET("/debug/pprof/trace", base, wrapHandlerFunc(httpProf.Trace))
+ for _, p := range pprof.Profiles() {
+ name := p.Name()
+ r.GET(fmt.Sprintf("/debug/pprof/%s", name), base, wrapHandler(httpProf.Handler(name)))
+ }
+}
+
+func wrapHandlerFunc(h http.HandlerFunc) router.Handler {
+ return func(c *router.Context) {
+ h(c.Writer, c.Request)
+ }
+}
+
+func wrapHandler(h http.Handler) router.Handler {
+ return func(c *router.Context) {
+ h.ServeHTTP(c.Writer, c.Request)
+ }
+}
« appengine/gaemiddleware/routes.go ('K') | « appengine/gaemiddleware/routes.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698