Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio authored Sep 25, 2024
2 parents df7911e + ac73f9b commit 53c80ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion profiler/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ var profileTypes = map[ProfileType]profileType{
Filename: "metrics.json",
Collect: func(p *profiler) ([]byte, error) {
var buf bytes.Buffer
p.interruptibleSleep(p.cfg.period)
interrupted := p.interruptibleSleep(p.cfg.period)
err := p.met.report(now(), &buf)
if err != nil && interrupted {
err = errProfilerStopped
}
return buf.Bytes(), err
},
},
Expand Down
18 changes: 14 additions & 4 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ var (
activeProfiler *profiler
containerID = internal.ContainerID() // replaced in tests
entityID = internal.EntityID() // replaced in tests

// errProfilerStopped is a sentinel for suppressng errors if we are
// about to stop the profiler
errProfilerStopped = errors.New("profiler stopped")
)

// Start starts the profiler. If the profiler is already running, it will be
Expand Down Expand Up @@ -343,9 +347,12 @@ func (p *profiler) collect(ticker <-chan time.Time) {
}
profs, err := p.runProfile(t)
if err != nil {
log.Error("Error getting %s profile: %v; skipping.", t, err)
tags := append(p.cfg.tags.Slice(), t.Tag())
p.cfg.statsd.Count("datadog.profiling.go.collect_error", 1, tags, 1)
if err != errProfilerStopped {
log.Error("Error getting %s profile: %v; skipping.", t, err)
tags := append(p.cfg.tags.Slice(), t.Tag())
p.cfg.statsd.Count("datadog.profiling.go.collect_error", 1, tags, 1)
}
return
}
mu.Lock()
defer mu.Unlock()
Expand Down Expand Up @@ -480,10 +487,13 @@ func (p *profiler) outputDir(bat batch) error {

// interruptibleSleep sleeps for the given duration or until interrupted by the
// p.exit channel being closed.
func (p *profiler) interruptibleSleep(d time.Duration) {
// Returns whether the sleep was interrupted
func (p *profiler) interruptibleSleep(d time.Duration) bool {
select {
case <-p.exit:
return true
case <-time.After(d):
return false
}
}

Expand Down

0 comments on commit 53c80ca

Please sign in to comment.