Skip to content

Commit

Permalink
Timeline - minor fixup
Browse files Browse the repository at this point in the history
Avoid a redundant nil check
  • Loading branch information
r1viollet committed Sep 3, 2024
1 parent 1d874d6 commit 8e2b9f6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,9 @@ func (r *DatadogReporter) reportProfile(ctx context.Context) error {
return err
}

func (r *DatadogReporter) processSample(sample *pprofile.Sample, profile *pprofile.Profile, traceKey traceAndMetaKey,
traceInfo *traceFramesCounts, fileIDtoMapping map[libpf.FileID]*pprofile.Mapping,
func (r *DatadogReporter) processSample(sample *pprofile.Sample, profile *pprofile.Profile,
traceKey *traceAndMetaKey, traceInfo *traceFramesCounts,
fileIDtoMapping map[libpf.FileID]*pprofile.Mapping,
frameIDtoFunction map[libpf.FrameID]*pprofile.Function,
funcMap map[funcInfo]*pprofile.Function) {
const unknownStr = "UNKNOWN"
Expand Down Expand Up @@ -481,7 +482,7 @@ func (r *DatadogReporter) processSample(sample *pprofile.Sample, profile *pprofi
}

sample.Label = make(map[string][]string)
var timestamps []uint64 = nil
var timestamps []uint64
if r.timeline {
timestamps = traceInfo.timestamps
}
Expand Down Expand Up @@ -520,7 +521,6 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile,
totalSampleCount := 0

for traceKey, traceInfo := range samples {

for _, ts := range traceInfo.timestamps {
if ts < startTS || startTS == 0 {
startTS = ts
Expand All @@ -532,7 +532,7 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile,
}
sample := &pprofile.Sample{}
count := len(traceInfo.timestamps)
r.processSample(sample, profile, traceKey, traceInfo, fileIDtoMapping,
r.processSample(sample, profile, &traceKey, traceInfo, fileIDtoMapping,
frameIDtoFunction, funcMap)
totalSampleCount += count
}
Expand Down Expand Up @@ -571,13 +571,11 @@ func createPprofFunctionEntry(funcMap map[funcInfo]*pprofile.Function,
return function
}

//nolint:gocritic
func addTraceLabels(labels map[string][]string, k traceAndMetaKey,
func addTraceLabels(labels map[string][]string, k *traceAndMetaKey,
baseExec string, timestamps []uint64) {
if k.comm != "" {
labels["thread_name"] = append(labels["thread_name"], k.comm)
}

if k.podName != "" {
labels["pod_name"] = append(labels["pod_name"], k.podName)
}
Expand Down Expand Up @@ -609,7 +607,7 @@ func addTraceLabels(labels map[string][]string, k traceAndMetaKey,
labels["process_name"] = append(labels["process_name"], baseExec)
}

if timestamps != nil && len(timestamps) > 0 {
if len(timestamps) > 0 {
timestampStrs := make([]string, 0, len(timestamps))
for _, ts := range timestamps {
timestampStrs = append(timestampStrs, strconv.FormatUint(ts, 10))
Expand Down

0 comments on commit 8e2b9f6

Please sign in to comment.