File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,16 @@ import (
6
6
"time"
7
7
)
8
8
9
- // Handler returns an http handler that requires a "seconds" query argument
10
- // and produces a profile over this duration. The optional "format" parameter
11
- // controls if the output is written in Google's "pprof" format (default) or
12
- // Brendan Gregg's "folded" stack format.
9
+ // Handler returns an http handler that takes an optional "seconds" query
10
+ // argument that defaults to "30" and produces a profile over this duration.
11
+ // The optional "format" parameter controls if the output is written in
12
+ // Google's "pprof" format (default) or Brendan Gregg's "folded" stack format.
13
13
func Handler () http.Handler {
14
14
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
15
15
var seconds int
16
- if _ , err := fmt .Sscanf (r .URL .Query ().Get ("seconds" ), "%d" , & seconds ); err != nil {
16
+ if s := r .URL .Query ().Get ("seconds" ); s == "" {
17
+ seconds = 30
18
+ } else if _ , err := fmt .Sscanf (s , "%d" , & seconds ); err != nil || seconds <= 0 {
17
19
w .WriteHeader (http .StatusBadRequest )
18
20
fmt .Fprintf (w , "bad seconds: %d: %s\n " , seconds , err )
19
21
}
You can’t perform that action at this time.
0 commit comments