...
1 package pprof
2
3 import (
4 "net/http"
5 "net/http/pprof"
6 "time"
7
8 "github.com/gorilla/mux"
9 )
10
11
12 func Serve(addr string) error {
13 router := Router()
14 server := &http.Server{
15 Addr: addr,
16 Handler: router,
17 ReadHeaderTimeout: 3 * time.Second,
18 }
19 return server.ListenAndServe()
20 }
21
22
23 func Router() *mux.Router {
24 r := mux.NewRouter()
25 r.PathPrefix("/debug/").Handler(http.DefaultServeMux)
26 r.HandleFunc("/debug/pprof/", pprof.Index)
27 r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
28 r.HandleFunc("/debug/pprof/profile", pprof.Profile)
29 r.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
30 r.HandleFunc("/debug/pprof/trace", pprof.Trace)
31 return r
32 }
33
View as plain text