DebugCollectProfile fetches a tar.gz archive of pprof profiles from the server. The caller is responsible for closing the returned ReadCloser.
(ctx context.Context, opts DebugProfileOptions)
| 30 | // DebugCollectProfile fetches a tar.gz archive of pprof profiles from the |
| 31 | // server. The caller is responsible for closing the returned ReadCloser. |
| 32 | func (c *Client) DebugCollectProfile(ctx context.Context, opts DebugProfileOptions) (io.ReadCloser, error) { |
| 33 | qp := url.Values{} |
| 34 | if opts.Duration > 0 { |
| 35 | qp.Set("duration", opts.Duration.String()) |
| 36 | } |
| 37 | if len(opts.Profiles) > 0 { |
| 38 | qp.Set("profiles", strings.Join(opts.Profiles, ",")) |
| 39 | } |
| 40 | |
| 41 | reqPath := "/api/v2/debug/profile" |
| 42 | if len(qp) > 0 { |
| 43 | reqPath += "?" + qp.Encode() |
| 44 | } |
| 45 | |
| 46 | resp, err := c.Request(ctx, http.MethodPost, reqPath, nil) |
| 47 | if err != nil { |
| 48 | return nil, xerrors.Errorf("request debug profile: %w", err) |
| 49 | } |
| 50 | if resp.StatusCode != http.StatusOK { |
| 51 | defer resp.Body.Close() |
| 52 | return nil, ReadBodyAsError(resp) |
| 53 | } |
| 54 | |
| 55 | return resp.Body, nil |
| 56 | } |