Skip to content

Commit 90cb49f

Browse files
committed
Make pprof the default format, remove guessing
@swatson314159 reported that the current behavior is confusing in GH issue #1, and I agree. Hopefully the new behavior is less surprising.
1 parent 517eaf9 commit 90cb49f

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Additionally fgprof supports the plain text format used by Brendan Gregg's [Flam
4848
```
4949
git clone https://github.com/brendangregg/FlameGraph
5050
cd FlameGraph
51-
curl -s 'localhost:6060/debug/fgprof?seconds=3' > fgprof.fold
52-
./flamegraph.pl fgprof.fold > fgprof.svg
51+
curl -s 'localhost:6060/debug/fgprof?seconds=3&format=folded' > fgprof.folded
52+
./flamegraph.pl fgprof.folded > fgprof.svg
5353
```
5454

5555
![](./assets/fgprof_gregg.png)

handler.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package fgprof
33
import (
44
"fmt"
55
"net/http"
6-
"strings"
76
"time"
87
)
98

109
// Handler returns an http handler that requires a "seconds" query argument
1110
// and produces a profile over this duration. The optional "format" parameter
12-
// controls if the output is written in Brendan Gregg's "folded" stack
13-
// format, or Google's "pprof" format. If no "format" is given, the handler
14-
// tries to guess the best format based on the http headers.
11+
// controls if the output is written in Google's "pprof" format (default) or
12+
// Brendan Gregg's "folded" stack format.
1513
func Handler() http.Handler {
1614
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1715
var seconds int
@@ -22,23 +20,11 @@ func Handler() http.Handler {
2220

2321
format := Format(r.URL.Query().Get("format"))
2422
if format == "" {
25-
format = guessFormat(r)
23+
format = FormatPprof
2624
}
2725

2826
stop := Start(w, format)
2927
defer stop()
3028
time.Sleep(time.Duration(seconds) * time.Second)
3129
})
3230
}
33-
34-
// guessFormat returns FormatPprof if it looks like pprof sent r, otherwise
35-
// FormatFolded. It's not meant to be a perfect heuristic, but a nice
36-
// convenience for users that don't want to specify the format explicitly.
37-
func guessFormat(r *http.Request) Format {
38-
for _, format := range r.Header["Accept-Encoding"] {
39-
if strings.ToLower(format) == "gzip" {
40-
return FormatPprof
41-
}
42-
}
43-
return FormatFolded
44-
}

0 commit comments

Comments
 (0)