]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/pprof: run GC for /debug/pprof/heap?gc=1
authorRuss Cox <rsc@golang.org>
Fri, 24 Oct 2014 14:58:13 +0000 (10:58 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 24 Oct 2014 14:58:13 +0000 (10:58 -0400)
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

index 0c7548e3ef3792adaeb6866081f6bf6aa0bc4159..a23f1bc4bc6026973a1faac1cd8bda9e82f70d5b 100644 (file)
@@ -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
 }