Skip to content

Commit 71ffca5

Browse files
authored
fix(ebpf): #2788 followup (#2789)
1 parent 131c5e3 commit 71ffca5

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

ebpf/pprof/pprof.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func (b ProfileBuilders) BuilderForTarget(hash uint64, labels labels.Labels) *Pr
5757
PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
5858
TimeNanos: time.Now().UnixNano(),
5959
},
60-
hash: xxhash.New(),
6160
tmpLocationIDs: make([]uint64, 0, 128),
61+
tmpLocations: make([]*profile.Location, 0, 128),
6262
}
6363
res = builder
6464
b.Builders[hash] = res
@@ -72,8 +72,6 @@ type ProfileBuilder struct {
7272
Profile *profile.Profile
7373
Labels labels.Labels
7474

75-
hash *xxhash.Digest
76-
b [8]byte
7775
tmpLocations []*profile.Location
7876
tmpLocationIDs []uint64
7977
}
@@ -91,37 +89,25 @@ func (p *ProfileBuilder) CreateSample(stacktrace []string, value uint64) {
9189

9290
func (p *ProfileBuilder) CreateSampleOrAddValue(stacktrace []string, value uint64) {
9391
scaledValue := int64(value) * p.Profile.Period
94-
if cap(p.tmpLocations) < len(stacktrace) {
95-
p.tmpLocations = make([]*profile.Location, 0, len(stacktrace))
96-
} else {
97-
p.tmpLocations = p.tmpLocations[:0]
98-
}
99-
if cap(p.tmpLocationIDs) < len(stacktrace) {
100-
p.tmpLocationIDs = make([]uint64, 0, len(stacktrace))
101-
} else {
102-
p.tmpLocationIDs = p.tmpLocationIDs[:0]
103-
}
92+
p.tmpLocations = p.tmpLocations[:0]
93+
p.tmpLocationIDs = p.tmpLocationIDs[:0]
10494
for _, s := range stacktrace {
10595
loc := p.addLocation(s)
10696
p.tmpLocations = append(p.tmpLocations, loc)
10797
p.tmpLocationIDs = append(p.tmpLocationIDs, loc.ID)
10898
}
109-
p.hash.Reset()
110-
if _, err := p.hash.Write(uint64Bytes(p.tmpLocationIDs)); err != nil {
111-
panic(err)
112-
}
113-
h := p.hash.Sum64()
99+
h := xxhash.Sum64(uint64Bytes(p.tmpLocationIDs))
114100
sample := p.sampleHashToSample[h]
115101
if sample != nil {
116102
sample.Value[0] += scaledValue
117103
return
118104
}
119105
sample = &profile.Sample{
120-
Location: p.tmpLocations,
106+
Location: make([]*profile.Location, len(p.tmpLocations)),
121107
Value: []int64{scaledValue},
122108
}
109+
copy(sample.Location, p.tmpLocations)
123110
p.sampleHashToSample[h] = sample
124-
p.tmpLocations = nil
125111
p.Profile.Sample = append(p.Profile.Sample, sample)
126112
}
127113

0 commit comments

Comments
 (0)