From c5943c668b919b98fd107c2327678ee32a868246 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 24 Oct 2014 10:58:13 -0400 Subject: [PATCH] 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 --- src/net/http/pprof/pprof.go | 4 ++++ 1 file changed, 4 insertions(+) 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 } -- 2.50.0