Skip to content

Commit

Permalink
fix: Emit a sample for each timestamp when timeline is enabled (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsavoire authored Dec 31, 2024
1 parent 4cebb32 commit 7b05379
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions reporter/datadog_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,24 @@ func (r *DatadogReporter) getPprofProfile() (profile *pprofile.Profile,
sample.Location = append(sample.Location, loc)
}

sample.Label = make(map[string][]string)
var timestamps []uint64
if r.timeline {
timestamps = traceInfo.timestamps
if !r.timeline {
count := int64(len(traceInfo.timestamps))
labels := make(map[string][]string)
addTraceLabels(labels, traceKey, processMeta.containerMetadata, baseExec, 0)
sample.Value = append(sample.Value, count, count*samplingPeriod)
sample.Label = labels
profile.Sample = append(profile.Sample, sample)
} else {
sample.Value = append(sample.Value, 1, samplingPeriod)
for _, ts := range traceInfo.timestamps {
sampleWithTimestamp := &pprofile.Sample{}
*sampleWithTimestamp = *sample
labels := make(map[string][]string)
addTraceLabels(labels, traceKey, processMeta.containerMetadata, baseExec, ts)
sampleWithTimestamp.Label = labels
profile.Sample = append(profile.Sample, sampleWithTimestamp)
}
}
addTraceLabels(sample.Label, traceKey, processMeta.containerMetadata, baseExec, timestamps)

count := int64(len(traceInfo.timestamps))
sample.Value = append(sample.Value, count, count*samplingPeriod)
profile.Sample = append(profile.Sample, sample)
totalSampleCount += len(traceInfo.timestamps)
}
log.Infof("Reporting pprof profile with %d samples from %v to %v",
Expand Down Expand Up @@ -622,7 +630,7 @@ func createPprofFunctionEntry(funcMap map[funcInfo]*pprofile.Function,
}

func addTraceLabels(labels map[string][]string, i traceAndMetaKey, containerMetadata containermetadata.ContainerMetadata,
baseExec string, timestamps []uint64) {
baseExec string, timestamp uint64) {
if i.comm != "" {
labels["thread_name"] = append(labels["thread_name"], i.comm)
}
Expand Down Expand Up @@ -658,13 +666,8 @@ func addTraceLabels(labels map[string][]string, i traceAndMetaKey, containerMeta
labels["process_name"] = append(labels["process_name"], baseExec)
}

if len(timestamps) > 0 {
timestampStrs := make([]string, 0, len(timestamps))
for _, ts := range timestamps {
timestampStrs = append(timestampStrs, strconv.FormatUint(ts, 10))
}
// Assign all timestamps as a single label entry
labels["end_timestamp_ns"] = timestampStrs
if timestamp != 0 {
labels["end_timestamp_ns"] = append(labels["end_timestamp_ns"], strconv.FormatUint(timestamp, 10))
}
}

Expand Down

0 comments on commit 7b05379

Please sign in to comment.