Skip to content

Commit

Permalink
Add trace of pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Mar 26, 2024
1 parent 1aa3b30 commit 8bc32a5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ func newHTTPRouter() *mux.Router {
r.Handle("/debug/pprof/block", &profileHandler{pprof.Handler("block")})
r.Handle("/debug/pprof/goroutine", &profileHandler{pprof.Handler("goroutine")})
r.Handle("/debug/pprof/threadcreate", &profileHandler{pprof.Handler("threadcreate")})
r.Handle("/debug/pprof/trace", &traceHandler{})
return r
}

Expand Down Expand Up @@ -557,3 +558,17 @@ func (p *profileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

p.pHandler.ServeHTTP(w, r)
}

type traceHandler struct {
}

func (p *traceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
queries := r.URL.Query()
password := queries.Get("password")
if !option.EnableProfiling || password != option.ProfilePassword {
http.Error(w, "", http.StatusUnauthorized)
return
}

pprof.Trace(w, r)
}

0 comments on commit 8bc32a5

Please sign in to comment.