From 8bc32a5252411d526ac549db5a974f6d1a675f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=B5=AB=E7=84=B6?= Date: Tue, 26 Mar 2024 17:18:38 +0800 Subject: [PATCH] Add trace of pprof --- fileserver/fileserver.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fileserver/fileserver.go b/fileserver/fileserver.go index a1d044f6..63d8ba8b 100644 --- a/fileserver/fileserver.go +++ b/fileserver/fileserver.go @@ -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 } @@ -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) +}