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 8496397
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (r *DatadogReporter) reportProfile(ctx context.Context) error {
return err
}

func (r *DatadogReporter) processSample(sample *pprofile.Sample, profile *pprofile.Profile, traceKey traceAndMetaKey,
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) {
Expand Down Expand Up @@ -481,7 +481,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 +520,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 +531,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 +570,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 +606,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 8496397

Please sign in to comment.