debug: limit the size of the trace

We've noticed that a trace that is captured over the full duration is
too large to open on most machines. A trace.out captured over just the
interval period (30s by default) should be a more than enough time to
capture trace data.
This commit is contained in:
Daniel Nephin 2022-02-15 14:10:07 -05:00
parent bf1e2d79f8
commit 5bd73fc218
2 changed files with 6 additions and 3 deletions

3
.changelog/12359.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
debug: reduce the capture time for trace to only a single interval instead of the full duration to make trace.out easier to open without running into OOM errors.
```

View File

@ -413,7 +413,7 @@ func (c *cmd) captureLongRunning(ctx context.Context) error {
g.Go(func() error { g.Go(func() error {
// use ctx without a timeout to allow the trace to finish sending // use ctx without a timeout to allow the trace to finish sending
return c.captureTrace(ctx, s) return c.captureTrace(ctx, int(c.interval.Seconds()))
}) })
} }
if c.captureTarget(targetLogs) { if c.captureTarget(targetLogs) {
@ -443,8 +443,8 @@ func (c *cmd) captureGoRoutines(outputDir string) error {
return ioutil.WriteFile(filepath.Join(outputDir, "goroutine.prof"), gr, 0644) return ioutil.WriteFile(filepath.Join(outputDir, "goroutine.prof"), gr, 0644)
} }
func (c *cmd) captureTrace(ctx context.Context, s float64) error { func (c *cmd) captureTrace(ctx context.Context, duration int) error {
prof, err := c.client.Debug().PProf(ctx, "trace", int(s)) prof, err := c.client.Debug().PProf(ctx, "trace", duration)
if err != nil { if err != nil {
return fmt.Errorf("failed to collect cpu profile: %w", err) return fmt.Errorf("failed to collect cpu profile: %w", err)
} }