]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/pprof: accept fractional seconds in trace handler
authorRuss Cox <rsc@golang.org>
Sun, 3 Apr 2016 16:52:12 +0000 (12:52 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 11 Apr 2016 14:29:10 +0000 (14:29 +0000)
For heavily loaded servers, even 1 second of trace is too large
to process with the trace viewer; using a float64 here allows
fetching /debug/pprof/trace?seconds=0.1.

Change-Id: I286c07abf04f9c1fe594b0e26799bf37f5c734db
Reviewed-on: https://go-review.googlesource.com/21455
Reviewed-by: Austin Clements <austin@google.com>
src/net/http/pprof/pprof.go

index 44afa2d8d89ad2cb1b8391796b80794831220a6e..cb4086b963b0e433cc3bc68c9442c2be0afc3cab 100644 (file)
@@ -120,8 +120,8 @@ func Profile(w http.ResponseWriter, r *http.Request) {
 // Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified.
 // The package initialization registers it as /debug/pprof/trace.
 func Trace(w http.ResponseWriter, r *http.Request) {
-       sec, _ := strconv.ParseInt(r.FormValue("seconds"), 10, 64)
-       if sec == 0 {
+       sec, err := strconv.ParseFloat(r.FormValue("seconds"), 64)
+       if sec <= 0 || err != nil {
                sec = 1
        }
 
@@ -136,7 +136,7 @@ func Trace(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Could not enable tracing: %s\n", err)
                return
        }
-       sleep(w, time.Duration(sec)*time.Second)
+       sleep(w, time.Duration(sec*float64(time.Second)))
        trace.Stop()
 }