|
@@ -18,12 +18,14 @@ import (
|
18
|
18
|
"bytes"
|
19
|
19
|
"fmt"
|
20
|
20
|
"io"
|
|
21
|
+ "io/ioutil"
|
21
|
22
|
"net/http"
|
22
|
23
|
"net/url"
|
23
|
24
|
"os"
|
24
|
25
|
"os/exec"
|
25
|
26
|
"path/filepath"
|
26
|
27
|
"strconv"
|
|
28
|
+ "strings"
|
27
|
29
|
"sync"
|
28
|
30
|
"time"
|
29
|
31
|
|
|
@@ -391,12 +393,24 @@ func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
|
391
|
393
|
return nil, fmt.Errorf("http fetch: %v", err)
|
392
|
394
|
}
|
393
|
395
|
if resp.StatusCode != http.StatusOK {
|
394
|
|
- return nil, fmt.Errorf("server response: %s", resp.Status)
|
|
396
|
+ defer resp.Body.Close()
|
|
397
|
+ return nil, statusCodeError(resp)
|
395
|
398
|
}
|
396
|
399
|
|
397
|
400
|
return resp.Body, nil
|
398
|
401
|
}
|
399
|
402
|
|
|
403
|
+func statusCodeError(resp *http.Response) error {
|
|
404
|
+ if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
|
|
405
|
+ // error is from pprof endpoint
|
|
406
|
+ body, err := ioutil.ReadAll(resp.Body)
|
|
407
|
+ if err == nil {
|
|
408
|
+ return fmt.Errorf("server response: %s - %s", resp.Status, body)
|
|
409
|
+ }
|
|
410
|
+ }
|
|
411
|
+ return fmt.Errorf("server response: %s", resp.Status)
|
|
412
|
+}
|
|
413
|
+
|
400
|
414
|
// isPerfFile checks if a file is in perf.data format. It also returns false
|
401
|
415
|
// if it encounters an error during the check.
|
402
|
416
|
func isPerfFile(path string) bool {
|