MCPcopy Index your code
hub / github.com/coder/coder / DebugCollectProfile

Method DebugCollectProfile

codersdk/debug.go:32–56  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

30// DebugCollectProfile fetches a tar.gz archive of pprof profiles from the
31// server. The caller is responsible for closing the returned ReadCloser.
32func (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}

Callers 2

TestDebugCollectProfileFunction · 0.80
PprofInfoFromArchiveFunction · 0.80

Calls 7

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
EncodeMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestDebugCollectProfileFunction · 0.64