| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT. |
| 5 |
// To regenerate this file run "make genpdata". |
| 6 |
|
| 7 |
package internal |
| 8 |
|
| 9 |
import ( |
| 10 |
"encoding/binary" |
| 11 |
"fmt" |
| 12 |
"sync" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/pdata/internal/json" |
| 15 |
"go.opentelemetry.io/collector/pdata/internal/proto" |
| 16 |
) |
| 17 |
|
| 18 |
// Sample represents each record value encountered within a profiled program. |
| 19 |
type Sample struct { |
| 20 |
StackIndex int32 |
| 21 |
Values []int64 |
| 22 |
AttributeIndices []int32 |
| 23 |
LinkIndex int32 |
| 24 |
TimestampsUnixNano []uint64 |
| 25 |
} |
| 26 |
|
| 27 |
var ( |
| 28 |
protoPoolSample = sync.Pool{ |
| 29 |
New: func() any { |
| 30 |
return &Sample{} |
| 31 |
}, |
| 32 |
} |
| 33 |
) |
| 34 |
|
| 35 |
func NewSample() *Sample { |
| 36 |
if !UseProtoPooling.IsEnabled() { |
| 37 |
return &Sample{} |
| 38 |
} |
| 39 |
return protoPoolSample.Get().(*Sample) |
| 40 |
} |
| 41 |
|
| 42 |
func DeleteSample(orig *Sample, nullable bool) { |
| 43 |
if orig == nil { |
| 44 |
return |
| 45 |
} |
| 46 |
|
| 47 |
if !UseProtoPooling.IsEnabled() { |
| 48 |
orig.Reset() |
| 49 |
return |
| 50 |
} |
| 51 |
|
| 52 |
orig.Reset() |
| 53 |
if nullable { |
| 54 |
protoPoolSample.Put(orig) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
func CopySample(dest, src *Sample) *Sample { |
| 59 |
// If copying to same object, just return. |
| 60 |
if src == dest { |
| 61 |
return dest |
| 62 |
} |
| 63 |
|
| 64 |
if src == nil { |
| 65 |
return nil |
| 66 |
} |
| 67 |
|
| 68 |
if dest == nil { |
| 69 |
dest = NewSample() |
| 70 |
} |
| 71 |
dest.StackIndex = src.StackIndex |
| 72 |
|
| 73 |
dest.Values = append(dest.Values[:0], src.Values...) |
| 74 |
dest.AttributeIndices = append(dest.AttributeIndices[:0], src.AttributeIndices...) |
| 75 |
dest.LinkIndex = src.LinkIndex |
| 76 |
|
| 77 |
dest.TimestampsUnixNano = append(dest.TimestampsUnixNano[:0], src.TimestampsUnixNano...) |
| 78 |
|
| 79 |
return dest |
| 80 |
} |
| 81 |
|
| 82 |
func CopySampleSlice(dest, src []Sample) []Sample { |
| 83 |
var newDest []Sample |
| 84 |
if cap(dest) < len(src) { |
| 85 |
newDest = make([]Sample, len(src)) |
| 86 |
} else { |
| 87 |
newDest = dest[:len(src)] |
| 88 |
// Cleanup the rest of the elements so GC can free the memory. |
| 89 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 90 |
for i := len(src); i < len(dest); i++ { |
| 91 |
DeleteSample(&dest[i], false) |
| 92 |
} |
| 93 |
} |
| 94 |
for i := range src { |
| 95 |
CopySample(&newDest[i], &src[i]) |
| 96 |
} |
| 97 |
return newDest |
| 98 |
} |
| 99 |
|
| 100 |
func CopySamplePtrSlice(dest, src []*Sample) []*Sample { |
| 101 |
var newDest []*Sample |
| 102 |
if cap(dest) < len(src) { |
| 103 |
newDest = make([]*Sample, len(src)) |
| 104 |
// Copy old pointers to re-use. |
| 105 |
copy(newDest, dest) |
| 106 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 107 |
for i := len(dest); i < len(src); i++ { |
| 108 |
newDest[i] = NewSample() |
| 109 |
} |
| 110 |
} else { |
| 111 |
newDest = dest[:len(src)] |
| 112 |
// Cleanup the rest of the elements so GC can free the memory. |
| 113 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 114 |
for i := len(src); i < len(dest); i++ { |
| 115 |
DeleteSample(dest[i], true) |
| 116 |
dest[i] = nil |
| 117 |
} |
| 118 |
// Add new pointers for missing elements. |
| 119 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 120 |
for i := len(dest); i < len(src); i++ { |
| 121 |
newDest[i] = NewSample() |
| 122 |
} |
| 123 |
} |
| 124 |
for i := range src { |
| 125 |
CopySample(newDest[i], src[i]) |
| 126 |
} |
| 127 |
return newDest |
| 128 |
} |
| 129 |
|
| 130 |
func (orig *Sample) Reset() { |
| 131 |
*orig = Sample{} |
| 132 |
} |
| 133 |
|
| 134 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 135 |
func (orig *Sample) MarshalJSON(dest *json.Stream) { |
| 136 |
dest.WriteObjectStart() |
| 137 |
if orig.StackIndex != int32(0) { |
| 138 |
dest.WriteObjectField("stackIndex") |
| 139 |
dest.WriteInt32(orig.StackIndex) |
| 140 |
} |
| 141 |
if len(orig.Values) > 0 { |
| 142 |
dest.WriteObjectField("values") |
| 143 |
dest.WriteArrayStart() |
| 144 |
dest.WriteInt64(orig.Values[0]) |
| 145 |
for i := 1; i < len(orig.Values); i++ { |
| 146 |
dest.WriteMore() |
| 147 |
dest.WriteInt64(orig.Values[i]) |
| 148 |
} |
| 149 |
dest.WriteArrayEnd() |
| 150 |
} |
| 151 |
if len(orig.AttributeIndices) > 0 { |
| 152 |
dest.WriteObjectField("attributeIndices") |
| 153 |
dest.WriteArrayStart() |
| 154 |
dest.WriteInt32(orig.AttributeIndices[0]) |
| 155 |
for i := 1; i < len(orig.AttributeIndices); i++ { |
| 156 |
dest.WriteMore() |
| 157 |
dest.WriteInt32(orig.AttributeIndices[i]) |
| 158 |
} |
| 159 |
dest.WriteArrayEnd() |
| 160 |
} |
| 161 |
if orig.LinkIndex != int32(0) { |
| 162 |
dest.WriteObjectField("linkIndex") |
| 163 |
dest.WriteInt32(orig.LinkIndex) |
| 164 |
} |
| 165 |
if len(orig.TimestampsUnixNano) > 0 { |
| 166 |
dest.WriteObjectField("timestampsUnixNano") |
| 167 |
dest.WriteArrayStart() |
| 168 |
dest.WriteUint64(orig.TimestampsUnixNano[0]) |
| 169 |
for i := 1; i < len(orig.TimestampsUnixNano); i++ { |
| 170 |
dest.WriteMore() |
| 171 |
dest.WriteUint64(orig.TimestampsUnixNano[i]) |
| 172 |
} |
| 173 |
dest.WriteArrayEnd() |
| 174 |
} |
| 175 |
dest.WriteObjectEnd() |
| 176 |
} |
| 177 |
|
| 178 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 179 |
func (orig *Sample) UnmarshalJSON(iter *json.Iterator) { |
| 180 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 181 |
switch f { |
| 182 |
case "stackIndex", "stack_index": |
| 183 |
orig.StackIndex = iter.ReadInt32() |
| 184 |
case "values": |
| 185 |
for iter.ReadArray() { |
| 186 |
orig.Values = append(orig.Values, iter.ReadInt64()) |
| 187 |
} |
| 188 |
|
| 189 |
case "attributeIndices", "attribute_indices": |
| 190 |
for iter.ReadArray() { |
| 191 |
orig.AttributeIndices = append(orig.AttributeIndices, iter.ReadInt32()) |
| 192 |
} |
| 193 |
|
| 194 |
case "linkIndex", "link_index": |
| 195 |
orig.LinkIndex = iter.ReadInt32() |
| 196 |
case "timestampsUnixNano", "timestamps_unix_nano": |
| 197 |
for iter.ReadArray() { |
| 198 |
orig.TimestampsUnixNano = append(orig.TimestampsUnixNano, iter.ReadUint64()) |
| 199 |
} |
| 200 |
|
| 201 |
default: |
| 202 |
iter.Skip() |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
func (orig *Sample) SizeProto() int { |
| 208 |
var n int |
| 209 |
var l int |
| 210 |
_ = l |
| 211 |
if orig.StackIndex != 0 { |
| 212 |
n += 1 + proto.Sov(uint64(orig.StackIndex)) |
| 213 |
} |
| 214 |
if len(orig.Values) > 0 { |
| 215 |
l = 0 |
| 216 |
for _, e := range orig.Values { |
| 217 |
l += proto.Sov(uint64(e)) |
| 218 |
} |
| 219 |
n += 1 + proto.Sov(uint64(l)) + l |
| 220 |
} |
| 221 |
if len(orig.AttributeIndices) > 0 { |
| 222 |
l = 0 |
| 223 |
for _, e := range orig.AttributeIndices { |
| 224 |
l += proto.Sov(uint64(e)) |
| 225 |
} |
| 226 |
n += 1 + proto.Sov(uint64(l)) + l |
| 227 |
} |
| 228 |
if orig.LinkIndex != 0 { |
| 229 |
n += 1 + proto.Sov(uint64(orig.LinkIndex)) |
| 230 |
} |
| 231 |
l = len(orig.TimestampsUnixNano) |
| 232 |
if l > 0 { |
| 233 |
l *= 8 |
| 234 |
n += 1 + proto.Sov(uint64(l)) + l |
| 235 |
} |
| 236 |
return n |
| 237 |
} |
| 238 |
|
| 239 |
func (orig *Sample) MarshalProto(buf []byte) int { |
| 240 |
pos := len(buf) |
| 241 |
var l int |
| 242 |
_ = l |
| 243 |
if orig.StackIndex != 0 { |
| 244 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.StackIndex)) |
| 245 |
pos-- |
| 246 |
buf[pos] = 0x8 |
| 247 |
} |
| 248 |
l = len(orig.Values) |
| 249 |
if l > 0 { |
| 250 |
endPos := pos |
| 251 |
for i := l - 1; i >= 0; i-- { |
| 252 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.Values[i])) |
| 253 |
} |
| 254 |
pos = proto.EncodeVarint(buf, pos, uint64(endPos-pos)) |
| 255 |
pos-- |
| 256 |
buf[pos] = 0x12 |
| 257 |
} |
| 258 |
l = len(orig.AttributeIndices) |
| 259 |
if l > 0 { |
| 260 |
endPos := pos |
| 261 |
for i := l - 1; i >= 0; i-- { |
| 262 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.AttributeIndices[i])) |
| 263 |
} |
| 264 |
pos = proto.EncodeVarint(buf, pos, uint64(endPos-pos)) |
| 265 |
pos-- |
| 266 |
buf[pos] = 0x1a |
| 267 |
} |
| 268 |
if orig.LinkIndex != 0 { |
| 269 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.LinkIndex)) |
| 270 |
pos-- |
| 271 |
buf[pos] = 0x20 |
| 272 |
} |
| 273 |
l = len(orig.TimestampsUnixNano) |
| 274 |
if l > 0 { |
| 275 |
for i := l - 1; i >= 0; i-- { |
| 276 |
pos -= 8 |
| 277 |
binary.LittleEndian.PutUint64(buf[pos:], uint64(orig.TimestampsUnixNano[i])) |
| 278 |
} |
| 279 |
pos = proto.EncodeVarint(buf, pos, uint64(l*8)) |
| 280 |
pos-- |
| 281 |
buf[pos] = 0x2a |
| 282 |
} |
| 283 |
return len(buf) - pos |
| 284 |
} |
| 285 |
|
| 286 |
func (orig *Sample) UnmarshalProto(buf []byte) error { |
| 287 |
var err error |
| 288 |
var fieldNum int32 |
| 289 |
var wireType proto.WireType |
| 290 |
|
| 291 |
l := len(buf) |
| 292 |
pos := 0 |
| 293 |
for pos < l { |
| 294 |
// If in a group parsing, move to the next tag. |
| 295 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 296 |
if err != nil { |
| 297 |
return err |
| 298 |
} |
| 299 |
switch fieldNum { |
| 300 |
|
| 301 |
case 1: |
| 302 |
if wireType != proto.WireTypeVarint { |
| 303 |
return fmt.Errorf("proto: wrong wireType = %d for field StackIndex", wireType) |
| 304 |
} |
| 305 |
var num uint64 |
| 306 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 307 |
if err != nil { |
| 308 |
return err |
| 309 |
} |
| 310 |
|
| 311 |
orig.StackIndex = int32(num) |
| 312 |
case 2: |
| 313 |
switch wireType { |
| 314 |
case proto.WireTypeLen: |
| 315 |
var length int |
| 316 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 317 |
if err != nil { |
| 318 |
return err |
| 319 |
} |
| 320 |
startPos := pos - length |
| 321 |
var num uint64 |
| 322 |
for startPos < pos { |
| 323 |
num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos) |
| 324 |
if err != nil { |
| 325 |
return err |
| 326 |
} |
| 327 |
orig.Values = append(orig.Values, int64(num)) |
| 328 |
} |
| 329 |
if startPos != pos { |
| 330 |
return fmt.Errorf("proto: invalid field len = %d for field Values", pos-startPos) |
| 331 |
} |
| 332 |
case proto.WireTypeVarint: |
| 333 |
var num uint64 |
| 334 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 335 |
if err != nil { |
| 336 |
return err |
| 337 |
} |
| 338 |
orig.Values = append(orig.Values, int64(num)) |
| 339 |
default: |
| 340 |
return fmt.Errorf("proto: wrong wireType = %d for field Values", wireType) |
| 341 |
} |
| 342 |
case 3: |
| 343 |
switch wireType { |
| 344 |
case proto.WireTypeLen: |
| 345 |
var length int |
| 346 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 347 |
if err != nil { |
| 348 |
return err |
| 349 |
} |
| 350 |
startPos := pos - length |
| 351 |
var num uint64 |
| 352 |
for startPos < pos { |
| 353 |
num, startPos, err = proto.ConsumeVarint(buf[:pos], startPos) |
| 354 |
if err != nil { |
| 355 |
return err |
| 356 |
} |
| 357 |
orig.AttributeIndices = append(orig.AttributeIndices, int32(num)) |
| 358 |
} |
| 359 |
if startPos != pos { |
| 360 |
return fmt.Errorf("proto: invalid field len = %d for field AttributeIndices", pos-startPos) |
| 361 |
} |
| 362 |
case proto.WireTypeVarint: |
| 363 |
var num uint64 |
| 364 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 365 |
if err != nil { |
| 366 |
return err |
| 367 |
} |
| 368 |
orig.AttributeIndices = append(orig.AttributeIndices, int32(num)) |
| 369 |
default: |
| 370 |
return fmt.Errorf("proto: wrong wireType = %d for field AttributeIndices", wireType) |
| 371 |
} |
| 372 |
|
| 373 |
case 4: |
| 374 |
if wireType != proto.WireTypeVarint { |
| 375 |
return fmt.Errorf("proto: wrong wireType = %d for field LinkIndex", wireType) |
| 376 |
} |
| 377 |
var num uint64 |
| 378 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 379 |
if err != nil { |
| 380 |
return err |
| 381 |
} |
| 382 |
|
| 383 |
orig.LinkIndex = int32(num) |
| 384 |
case 5: |
| 385 |
switch wireType { |
| 386 |
case proto.WireTypeLen: |
| 387 |
var length int |
| 388 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 389 |
if err != nil { |
| 390 |
return err |
| 391 |
} |
| 392 |
startPos := pos - length |
| 393 |
size := length / 8 |
| 394 |
orig.TimestampsUnixNano = make([]uint64, size) |
| 395 |
var num uint64 |
| 396 |
for i := 0; i < size; i++ { |
| 397 |
num, startPos, err = proto.ConsumeI64(buf[:pos], startPos) |
| 398 |
if err != nil { |
| 399 |
return err |
| 400 |
} |
| 401 |
orig.TimestampsUnixNano[i] = uint64(num) |
| 402 |
} |
| 403 |
if startPos != pos { |
| 404 |
return fmt.Errorf("proto: invalid field len = %d for field TimestampsUnixNano", pos-startPos) |
| 405 |
} |
| 406 |
case proto.WireTypeI64: |
| 407 |
var num uint64 |
| 408 |
num, pos, err = proto.ConsumeI64(buf, pos) |
| 409 |
if err != nil { |
| 410 |
return err |
| 411 |
} |
| 412 |
orig.TimestampsUnixNano = append(orig.TimestampsUnixNano, uint64(num)) |
| 413 |
default: |
| 414 |
return fmt.Errorf("proto: wrong wireType = %d for field TimestampsUnixNano", wireType) |
| 415 |
} |
| 416 |
default: |
| 417 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 418 |
if err != nil { |
| 419 |
return err |
| 420 |
} |
| 421 |
} |
| 422 |
} |
| 423 |
return nil |
| 424 |
} |
| 425 |
|
| 426 |
func GenTestSample() *Sample { |
| 427 |
orig := NewSample() |
| 428 |
orig.StackIndex = int32(13) |
| 429 |
orig.Values = []int64{int64(0), int64(13)} |
| 430 |
orig.AttributeIndices = []int32{int32(0), int32(13)} |
| 431 |
orig.LinkIndex = int32(13) |
| 432 |
orig.TimestampsUnixNano = []uint64{uint64(0), uint64(13)} |
| 433 |
return orig |
| 434 |
} |
| 435 |
|
| 436 |
func GenTestSamplePtrSlice() []*Sample { |
| 437 |
orig := make([]*Sample, 5) |
| 438 |
orig[0] = NewSample() |
| 439 |
orig[1] = GenTestSample() |
| 440 |
orig[2] = NewSample() |
| 441 |
orig[3] = GenTestSample() |
| 442 |
orig[4] = NewSample() |
| 443 |
return orig |
| 444 |
} |
| 445 |
|
| 446 |
func GenTestSampleSlice() []Sample { |
| 447 |
orig := make([]Sample, 5) |
| 448 |
orig[1] = *GenTestSample() |
| 449 |
orig[3] = *GenTestSample() |
| 450 |
return orig |
| 451 |
} |