示例#1
0
文件: weasel.go 项目: fortytw2/weasel
func handler() http.Handler {
	info := struct {
		Profiles []*pprof.Profile
		Token    string
	}{
		Profiles: pprof.Profiles(),
	}

	h := func(w http.ResponseWriter, r *http.Request) {
		// get the last path, allowing this to be mounted under any prefix
		split := strings.Split(r.URL.Path, "/")
		name := split[len(split)-1]

		switch name {
		case "":
			// Index page.
			if err := indexTmpl.Execute(w, info); err != nil {
				fmt.Fprintf(w, "something went wrong - %s", err)
				return
			}
		case "cmdline":
			nhpprof.Cmdline(w, r)
		case "profile":
			nhpprof.Profile(w, r)
		case "trace":
			nhpprof.Trace(w, r)
		case "symbol":
			nhpprof.Symbol(w, r)
		default:
			// Provides access to all profiles under runtime/pprof
			nhpprof.Handler(name).ServeHTTP(w, r)
		}
	}
	return http.HandlerFunc(h)
}
示例#2
0
文件: pprof.go 项目: tsuru/tsuru
// title: profile trace handler
// path: /debug/pprof/trace
// method: GET
// responses:
//   200: Ok
//   401: Unauthorized
func traceHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	if !permission.Check(t, permission.PermDebug) {
		return permission.ErrUnauthorized
	}
	pprof.Trace(w, r)
	return nil
}
示例#3
0
文件: config.go 项目: issue9/web
// 根据 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
}
示例#4
0
func (*Pprof) Index(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	switch p.ByName("name") {
	case "profile":
		pprof.Profile(w, r)
	case "symbol":
		pprof.Symbol(w, r)
	case "trace":
		pprof.Trace(w, r)
	case "cmdline":
		pprof.Cmdline(w, r)
	default:
		pprof.Index(w, r)
	}
}
示例#5
0
//Trace profiler on wrapper RouteFunction
func TraceHandler(fn restful.RouteFunction) restful.RouteFunction {
	return func(r *restful.Request, w *restful.Response) {
		pprof.Trace(w.ResponseWriter, r.Request)
		fn(r, w)
	}
}
示例#6
0
// Trace provides the pprof Trace endpoint
func (p *PProf) Trace(c *Context, next NextHandler) {
	pprof.Trace(c.Res, c.Req)
	next(c)
}