Commit 90b7058e authored by Kale Blankenship's avatar Kale Blankenship Committed by Brad Fitzpatrick

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/45812Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e1c9a371
...@@ -13,11 +13,13 @@ import ( ...@@ -13,11 +13,13 @@ import (
"crypto/tls" "crypto/tls"
"debug/dwarf" "debug/dwarf"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
...@@ -82,11 +84,22 @@ func getProfile(source string, timeout time.Duration) (*profile.Profile, error) ...@@ -82,11 +84,22 @@ func getProfile(source string, timeout time.Duration) (*profile.Profile, error)
return nil, err return nil, err
} }
if resp.StatusCode != http.StatusOK { 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) 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. // cpuProfileHandler is the Go pprof CPU profile handler URL.
const cpuProfileHandler = "/debug/pprof/profile" const cpuProfileHandler = "/debug/pprof/profile"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment