From: Russ Cox Date: Fri, 24 Oct 2014 14:58:13 +0000 (-0400) Subject: net/http/pprof: run GC for /debug/pprof/heap?gc=1 X-Git-Tag: go1.4beta1~50 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c5943c668b919b98fd107c2327678ee32a868246;p=gostls13.git net/http/pprof: run GC for /debug/pprof/heap?gc=1 We force runtime.GC before WriteHeapProfile with -test.heapprofile. Make it possible to do the same with the HTTP interface. Some servers only run a GC every few minutes. On such servers, the heap profile will be a few minutes stale, which may be too old to be useful. Requested by private mail. LGTM=dvyukov R=dvyukov CC=golang-codereviews https://golang.org/cl/161990043 --- diff --git a/src/net/http/pprof/pprof.go b/src/net/http/pprof/pprof.go index 0c7548e3ef..a23f1bc4bc 100644 --- a/src/net/http/pprof/pprof.go +++ b/src/net/http/pprof/pprof.go @@ -162,6 +162,10 @@ func (name handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Unknown profile: %s\n", name) return } + gc, _ := strconv.Atoi(r.FormValue("gc")) + if name == "heap" && gc > 0 { + runtime.GC() + } p.WriteTo(w, debug) return }