mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add pprof endpoints, additional spans (#770)
i would split this commit in two if i were a good dev. the pprof stuff is really useful and this only samples when called. this is pretty standard go service stuff. expvar is cool, too. the additional spannos have turned up some interesting tid bits... gonna slide em in
This commit is contained in:
38
api/server/profile.go
Normal file
38
api/server/profile.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Replicated from expvar.go as not public.
|
||||
func expVars(w http.ResponseWriter, r *http.Request) {
|
||||
first := true
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
fmt.Fprintf(w, "{\n")
|
||||
expvar.Do(func(kv expvar.KeyValue) {
|
||||
if !first {
|
||||
fmt.Fprintf(w, ",\n")
|
||||
}
|
||||
first = false
|
||||
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
|
||||
})
|
||||
fmt.Fprintf(w, "\n}\n")
|
||||
}
|
||||
|
||||
func profilerSetup(router *gin.Engine, path string) {
|
||||
engine := router.Group(path)
|
||||
engine.Any("/vars", gin.WrapF(expVars))
|
||||
engine.Any("/pprof/", gin.WrapF(pprof.Index))
|
||||
engine.Any("/pprof/cmdline", gin.WrapF(pprof.Cmdline))
|
||||
engine.Any("/pprof/profile", gin.WrapF(pprof.Profile))
|
||||
engine.Any("/pprof/symbol", gin.WrapF(pprof.Symbol))
|
||||
engine.Any("/pprof/block", gin.WrapF(pprof.Handler("block").ServeHTTP))
|
||||
engine.Any("/pprof/heap", gin.WrapF(pprof.Handler("heap").ServeHTTP))
|
||||
engine.Any("/pprof/goroutine", gin.WrapF(pprof.Handler("goroutine").ServeHTTP))
|
||||
engine.Any("/pprof/threadcreate", gin.WrapF(pprof.Handler("threadcreate").ServeHTTP))
|
||||
}
|
||||
Reference in New Issue
Block a user