本文整理汇总了Golang中net/http/pprof.Index函数的典型用法代码示例。如果您正苦于以下问题:Golang Index函数的具体用法?Golang Index怎么用?Golang Index使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Index函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
func (this *ProfController) Get() {
ptype := this.Ctx.Params[":pp"]
if ptype == "" {
pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
} else if ptype == "cmdline" {
pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
} else if ptype == "profile" {
pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
} else if ptype == "symbol" {
pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
} else {
pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
}
this.Ctx.ResponseWriter.WriteHeader(200)
}
示例2: Get
func (this *ProfController) Get() {
switch this.Ctx.Params[":pp"] {
default:
pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
case "":
pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
case "cmdline":
pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
case "profile":
pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
case "symbol":
pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
}
this.Ctx.ResponseWriter.WriteHeader(200)
}
示例3: ServeHTTP
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
//h.statMap.Add(statRequest, 1)
counter := metrics.GetOrRegisterCounter(statRequest, h.statMap)
counter.Inc(1)
meter := metrics.GetOrRegisterMeter(statRequestNew, h.statMap)
meter.Mark(1)
// FIXME(benbjohnson): Add pprof enabled flag.
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
} else {
h.mux.ServeHTTP(w, r)
return
}
}
示例4: indexHandler
func indexHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
if !permission.Check(t, permission.PermDebug) {
return permission.ErrUnauthorized
}
pprof.Index(w, r)
return nil
}
示例5: ServeHTTP
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
return
}
switch r.URL.Path {
case "/":
h.serveRoot(w, r)
case "/top":
h.serveTop(w, r)
case "/top/stats":
h.serveTopStats(w, r)
case "/repositories":
h.serveRepositories(w, r)
case "/backup":
h.serveBackup(w, r)
case "/debug/vars":
h.serveExpvars(w, r)
default:
http.NotFound(w, r)
}
}
示例6: ServeHTTP
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.statMap.Add(statRequest, 1)
// FIXME(benbjohnson): Add pprof enabled flag.
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
serveExpvar(w, r)
} else {
method := r.Method
if method == "" {
method = "GET"
}
if mux, ok := h.methodMux[method]; ok {
mux.ServeHTTP(w, r)
}
}
}
示例7: routerV01
func (hs *httpSrv) routerV01(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/ping":
hs.pingHandler(w, req)
case "/debug/pprof":
setPub(w)
httpprof.Index(w, req)
case "/debug/pprof/block":
hs.debugRuntime(w, req, "block")
case "/debug/pprof/goroutine":
hs.debugRuntime(w, req, "goroutine")
case "/debug/pprof/heap":
hs.debugRuntime(w, req, "heap")
case "/debug/pprof/threadcreate":
hs.debugRuntime(w, req, "threadcreate")
case "/debug/pprof/profile":
setPub(w)
httpprof.Profile(w, req)
case "/debug/pprof/cmdline":
setPub(w)
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
setPub(w)
httpprof.Symbol(w, req)
default:
RespondV1(w, 404, "page not found")
}
}
示例8: setupHandlers
func setupHandlers(metricSink *metricsink.MetricSink, podLister *cache.StoreToPodLister) http.Handler {
runningInKubernetes := true
// Make API handler.
wsContainer := restful.NewContainer()
wsContainer.EnableContentEncoding(true)
wsContainer.Router(restful.CurlyRouter{})
a := v1.NewApi(runningInKubernetes, metricSink)
a.Register(wsContainer)
// Metrics API
m := metricsApi.NewApi(metricSink, podLister)
m.Register(wsContainer)
handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
switch name {
case "profile":
pprof.Profile(resp, req.Request)
case "symbol":
pprof.Symbol(resp, req.Request)
case "cmdline":
pprof.Cmdline(resp, req.Request)
default:
pprof.Index(resp, req.Request)
}
}
// Setup pporf handlers.
ws := new(restful.WebService).Path(pprofBasePath)
ws.Route(ws.GET("/{subpath:*}").To(metrics.InstrumentRouteFunc("pprof", handlePprofEndpoint))).Doc("pprof endpoint")
wsContainer.Add(ws)
return wsContainer
}
示例9: ServeHTTP
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
atomic.AddInt64(&h.stats.Requests, 1)
atomic.AddInt64(&h.stats.ActiveRequests, 1)
defer atomic.AddInt64(&h.stats.ActiveRequests, -1)
start := time.Now()
// Add version header to all InfluxDB requests.
w.Header().Add("X-Influxdb-Version", h.Version)
// FIXME(benbjohnson): Add pprof enabled flag.
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
h.serveExpvar(w, r)
} else {
h.mux.ServeHTTP(w, r)
}
atomic.AddInt64(&h.stats.RequestDuration, time.Since(start).Nanoseconds())
}
示例10: debugRouter
func (s *httpServer) debugRouter(w http.ResponseWriter, req *http.Request) error {
switch req.URL.Path {
case "/debug":
util.NegotiateAPIResponseWrapper(w, req,
func() (interface{}, error) { return s.doDebug(req) })
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
}
return nil
}
示例11: ServeHTTP
func (s *UnitedAdmin) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if !utils.AllowMethod(w, req.Method, "HEAD", "GET", "POST", "PUT", "DELETE") {
return
}
if strings.HasPrefix(req.URL.Path, queuePrefixV1) {
key := req.URL.Path[len(queuePrefixV1):]
s.queueHandler(w, req, key)
return
} else if strings.HasPrefix(req.URL.Path, adminPrefixV1) {
key := req.URL.Path[len(adminPrefixV1):]
s.adminHandler(w, req, key)
return
} else if strings.HasPrefix(req.URL.Path, pprofPrefixCmd) {
httpprof.Cmdline(w, req)
return
} else if strings.HasPrefix(req.URL.Path, pprofPrefixProfile) {
httpprof.Profile(w, req)
return
} else if strings.HasPrefix(req.URL.Path, pprofPrefixSymbol) {
httpprof.Symbol(w, req)
return
} else if strings.HasPrefix(req.URL.Path, pprofPrefixIndex) {
httpprof.Index(w, req)
return
}
http.Error(w, "404 Not Found!", http.StatusNotFound)
return
}
示例12: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/registration":
s.registerHandler(w, req)
case "/ping":
s.pingHandler(w, req)
case "/info":
s.infoHandler(w, req)
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
log.Printf("ERROR: 404 %s", req.URL.Path)
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
示例13: ServeHTTP
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.statMap.Add(statRequest, 1)
h.statMap.Add(statRequestsActive, 1)
start := time.Now()
// FIXME(benbjohnson): Add pprof enabled flag.
if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
serveExpvar(w, r)
} else {
h.mux.ServeHTTP(w, r)
}
h.statMap.Add(statRequestsActive, -1)
h.statMap.Add(statRequestDuration, time.Since(start).Nanoseconds())
}
示例14: buildPprof
// 根据 config.Pprof 决定是否包装调试地址
func (cfg *Config) buildPprof(h http.Handler) http.Handler {
if len(cfg.Pprof) > 0 {
logs.Debug("web:", "开启了调试功能,地址为:", cfg.Pprof)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, cfg.Pprof) {
h.ServeHTTP(w, r)
return
}
path := r.URL.Path[len(cfg.Pprof):]
switch path {
case "cmdline":
pprof.Cmdline(w, r)
case "profile":
pprof.Profile(w, r)
case "symbol":
pprof.Symbol(w, r)
case "trace":
pprof.Trace(w, r)
default:
pprof.Index(w, r)
}
})
}
return h
}
示例15: Index
// Index responds with the pprof-formatted profile named by the request.
func (c *PProfContext) Index(rw web.ResponseWriter, req *web.Request) {
// PPROF will automatically make paths for you. Need to make sure that the index has a / at the end.
if !strings.HasSuffix(req.URL.Path, "/") {
http.Redirect(rw, req.Request, req.URL.Path+"/", http.StatusMovedPermanently)
return
}
pprof.Index(rw, req.Request)
}