aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorKale Blankenship <kale@lemnisys.com>2017-06-14 17:39:03 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2017-06-15 02:14:24 +0000
commit90b7058ec4b73fe1da0e94ccd80d78835b6e32cb (patch)
tree0d274626ec942f17471bea7b1e208af53c341823 /src/cmd
parente1c9a371bb741f8b2d602c1dddab5c5c52d97931 (diff)
downloadgo-90b7058ec4b73fe1da0e94ccd80d78835b6e32cb.tar.xz
cmd/pprof: restore printing descriptive errors from net/http/pprof endpoints
Restores functionality added in https://golang.org/cl/35564/ which was lost in https://golang.org/cl/36798/ by the addition of the custom fetcher to src/cmd/pprof/pprof.go. The custom fetcher overrides the upstream default. Change-Id: Ic71e5e475d043276d916298ab5acb5c9b9ad063e Reviewed-on: https://go-review.googlesource.com/45812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/pprof/pprof.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cmd/pprof/pprof.go b/src/cmd/pprof/pprof.go
index 24bec07d97..2f3268cbc4 100644
--- a/src/cmd/pprof/pprof.go
+++ b/src/cmd/pprof/pprof.go
@@ -13,11 +13,13 @@ import (
"crypto/tls"
"debug/dwarf"
"fmt"
+ "io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
+ "strings"
"sync"
"time"
@@ -82,11 +84,22 @@ func getProfile(source string, timeout time.Duration) (*profile.Profile, error)
return nil, err
}
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("server response: %s", resp.Status)
+ defer resp.Body.Close()
+ return nil, statusCodeError(resp)
}
return profile.Parse(resp.Body)
}
+func statusCodeError(resp *http.Response) error {
+ if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
+ // error is from pprof endpoint
+ if body, err := ioutil.ReadAll(resp.Body); err == nil {
+ return fmt.Errorf("server response: %s - %s", resp.Status, body)
+ }
+ }
+ return fmt.Errorf("server response: %s", resp.Status)
+}
+
// cpuProfileHandler is the Go pprof CPU profile handler URL.
const cpuProfileHandler = "/debug/pprof/profile"