From fd3d644efdbdc484ce036d94e476ef0116f6a337 Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Tue, 1 Mar 2022 08:08:30 -0500 Subject: [PATCH] profiler: make delta profile check logic more clean Removed a redundant condition (deltaProfile is documented to return nil if delta profiles are disabled) and changed the order of conditions to match the default configuration (detla profiles first). --- profiler/profile.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/profiler/profile.go b/profiler/profile.go index a3d82e07a1..5fc140fadb 100644 --- a/profiler/profile.go +++ b/profiler/profile.go @@ -223,18 +223,17 @@ func (p *profiler) runProfile(pt ProfileType) ([]*profile, error) { end := now() tags := append(p.cfg.tags, pt.Tag()) var profs []*profile - if !p.cfg.deltaProfiles || deltaProf == nil { + if deltaProf != nil { + profs = append(profs, deltaProf) + p.cfg.statsd.Timing("datadog.profiler.go.delta_time", end.Sub(deltaStart), tags, 1) + } else { + // If the user has disabled delta profiles, or the profile type + // doesn't support delta profiles (like the CPU profile) then + // send the original profile unchanged. profs = append(profs, &profile{ name: t.Filename, data: data, }) - } else { - // If the user has enabled delta profiles, then the delta - // profile is all we need for the backend and we can save - // significant storage and bandwidth by not including the full, - // non-delta profile. - profs = append(profs, deltaProf) - p.cfg.statsd.Timing("datadog.profiler.go.delta_time", end.Sub(deltaStart), tags, 1) } p.cfg.statsd.Timing("datadog.profiler.go.collect_time", end.Sub(start), tags, 1) return profs, nil