コード例 #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
ファイル: pprof.go プロジェクト: DavidZhangqin/goweb
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
ファイル: aspects.go プロジェクト: abhiunc/go-restful
//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
ファイル: basecontrollers.go プロジェクト: influx6/relay
// Trace provides the pprof Trace endpoint
func (p *PProf) Trace(c *Context, next NextHandler) {
	pprof.Trace(c.Res, c.Req)
	next(c)
}