From 849639749c6eae9b50e5aae4c39766a541373eff Mon Sep 17 00:00:00 2001 From: r1viollet Date: Tue, 3 Sep 2024 14:28:44 +0200 Subject: [PATCH] Timeline - minor fixup Avoid a redundant nil check --- reporter/datadog_reporter.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/reporter/datadog_reporter.go b/reporter/datadog_reporter.go index 35d154d..d103f64 100644 --- a/reporter/datadog_reporter.go +++ b/reporter/datadog_reporter.go @@ -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) { @@ -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 } @@ -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 @@ -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 } @@ -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) } @@ -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))