@@ -57,8 +57,8 @@ func (b ProfileBuilders) BuilderForTarget(hash uint64, labels labels.Labels) *Pr
57
57
PeriodType : & profile.ValueType {Type : "cpu" , Unit : "nanoseconds" },
58
58
TimeNanos : time .Now ().UnixNano (),
59
59
},
60
- hash : xxhash .New (),
61
60
tmpLocationIDs : make ([]uint64 , 0 , 128 ),
61
+ tmpLocations : make ([]* profile.Location , 0 , 128 ),
62
62
}
63
63
res = builder
64
64
b .Builders [hash ] = res
@@ -72,8 +72,6 @@ type ProfileBuilder struct {
72
72
Profile * profile.Profile
73
73
Labels labels.Labels
74
74
75
- hash * xxhash.Digest
76
- b [8 ]byte
77
75
tmpLocations []* profile.Location
78
76
tmpLocationIDs []uint64
79
77
}
@@ -91,37 +89,25 @@ func (p *ProfileBuilder) CreateSample(stacktrace []string, value uint64) {
91
89
92
90
func (p * ProfileBuilder ) CreateSampleOrAddValue (stacktrace []string , value uint64 ) {
93
91
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 ]
104
94
for _ , s := range stacktrace {
105
95
loc := p .addLocation (s )
106
96
p .tmpLocations = append (p .tmpLocations , loc )
107
97
p .tmpLocationIDs = append (p .tmpLocationIDs , loc .ID )
108
98
}
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 ))
114
100
sample := p .sampleHashToSample [h ]
115
101
if sample != nil {
116
102
sample .Value [0 ] += scaledValue
117
103
return
118
104
}
119
105
sample = & profile.Sample {
120
- Location : p .tmpLocations ,
106
+ Location : make ([] * profile. Location , len ( p .tmpLocations )) ,
121
107
Value : []int64 {scaledValue },
122
108
}
109
+ copy (sample .Location , p .tmpLocations )
123
110
p .sampleHashToSample [h ] = sample
124
- p .tmpLocations = nil
125
111
p .Profile .Sample = append (p .Profile .Sample , sample )
126
112
}
127
113
0 commit comments