Skip to content

Commit 66ab7d9

Browse files
authored
Merge pull request #4 from felixge/gh-3
Default to 30s duration like net/http/pprof
2 parents c14b6f4 + 7b3aa0f commit 66ab7d9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

handler.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import (
66
"time"
77
)
88

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.
1313
func Handler() http.Handler {
1414
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1515
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 {
1719
w.WriteHeader(http.StatusBadRequest)
1820
fmt.Fprintf(w, "bad seconds: %d: %s\n", seconds, err)
1921
}

0 commit comments

Comments
 (0)