(sample *Sample)
| 194 | } |
| 195 | |
| 196 | func (pm *profileMerger) sampleKey(sample *Sample) sampleKey { |
| 197 | // Accumulate contents into a string. |
| 198 | var buf strings.Builder |
| 199 | buf.Grow(64) // Heuristic to avoid extra allocs |
| 200 | |
| 201 | // encode a number |
| 202 | putNumber := func(v uint64) { |
| 203 | var num [binary.MaxVarintLen64]byte |
| 204 | n := binary.PutUvarint(num[:], v) |
| 205 | buf.Write(num[:n]) |
| 206 | } |
| 207 | |
| 208 | // encode a string prefixed with its length. |
| 209 | putDelimitedString := func(s string) { |
| 210 | putNumber(uint64(len(s))) |
| 211 | buf.WriteString(s) |
| 212 | } |
| 213 | |
| 214 | for _, l := range sample.Location { |
| 215 | // Get the location in the merged profile, which may have a different ID. |
| 216 | if loc := pm.mapLocation(l); loc != nil { |
| 217 | putNumber(loc.ID) |
| 218 | } |
| 219 | } |
| 220 | putNumber(0) // Delimiter |
| 221 | |
| 222 | for _, l := range sortedKeys1(sample.Label) { |
| 223 | putDelimitedString(l) |
| 224 | values := sample.Label[l] |
| 225 | putNumber(uint64(len(values))) |
| 226 | for _, v := range values { |
| 227 | putDelimitedString(v) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | for _, l := range sortedKeys2(sample.NumLabel) { |
| 232 | putDelimitedString(l) |
| 233 | values := sample.NumLabel[l] |
| 234 | putNumber(uint64(len(values))) |
| 235 | for _, v := range values { |
| 236 | putNumber(uint64(v)) |
| 237 | } |
| 238 | units := sample.NumUnit[l] |
| 239 | putNumber(uint64(len(units))) |
| 240 | for _, v := range units { |
| 241 | putDelimitedString(v) |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return sampleKey(buf.String()) |
| 246 | } |
| 247 | |
| 248 | type sampleKey string |
| 249 |
no test coverage detected