fetch fetches a profile from source, within the timeout specified, producing messages through the ui. It returns the profile and the url of the actual source of the profile for remote profiles.
(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper)
| 494 | // producing messages through the ui. It returns the profile and the |
| 495 | // url of the actual source of the profile for remote profiles. |
| 496 | func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, src string, err error) { |
| 497 | var f io.ReadCloser |
| 498 | |
| 499 | // First determine whether the source is a file, if not, it will be treated as a URL. |
| 500 | if _, err = os.Stat(source); err == nil { |
| 501 | if isPerfFile(source) { |
| 502 | f, err = convertPerfData(source, ui) |
| 503 | } else { |
| 504 | f, err = os.Open(source) |
| 505 | } |
| 506 | } else { |
| 507 | sourceURL, timeout := adjustURL(source, duration, timeout) |
| 508 | if sourceURL != "" { |
| 509 | ui.Print("Fetching profile over HTTP from " + sourceURL) |
| 510 | if duration > 0 { |
| 511 | ui.Print(fmt.Sprintf("Please wait... (%v)", duration)) |
| 512 | } |
| 513 | f, err = fetchURL(sourceURL, timeout, tr) |
| 514 | src = sourceURL |
| 515 | } |
| 516 | } |
| 517 | if err == nil { |
| 518 | defer f.Close() |
| 519 | p, err = profile.Parse(f) |
| 520 | } |
| 521 | return |
| 522 | } |
| 523 | |
| 524 | // fetchURL fetches a profile from a URL using HTTP. |
| 525 | func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.ReadCloser, error) { |
no test coverage detected
searching dependent graphs…