Debian Codegraph @

pdata/pprofile/sample.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
5
6 import "fmt"
7
8 // switchDictionary updates the Sample, switching its indices from one
9 // dictionary to another.
10 func (ms Sample) switchDictionary(src, dst ProfilesDictionary) error {
11 for i, v := range ms.AttributeIndices().All() {
12 if src.AttributeTable().Len() < int(v) {
13 return fmt.Errorf("invalid attribute index %d", v)
14 }
15
16 attr := src.AttributeTable().At(int(v))
17 err := attr.switchDictionary(src, dst)
18 if err != nil {
19 return fmt.Errorf("couldn't switch dictionary for attribute %d: %w", i, err)
20 }
21 idx, err := SetAttribute(dst.AttributeTable(), attr)
22 if err != nil {
23 return fmt.Errorf("couldn't set attribute %d: %w", i, err)
24 }
25 ms.AttributeIndices().SetAt(i, idx)
26 }
27
28 if ms.LinkIndex() > 0 {
29 if src.LinkTable().Len() < int(ms.LinkIndex()) {
30 return fmt.Errorf("invalid link index %d", ms.LinkIndex())
31 }
32
33 idx, err := SetLink(dst.LinkTable(), src.LinkTable().At(int(ms.LinkIndex())))
34 if err != nil {
35 return fmt.Errorf("couldn't set link: %w", err)
36 }
37 ms.SetLinkIndex(idx)
38 }
39
40 if ms.StackIndex() > 0 {
41 if src.StackTable().Len() < int(ms.StackIndex()) {
42 return fmt.Errorf("invalid stack index %d", ms.StackIndex())
43 }
44
45 stack := src.StackTable().At(int(ms.StackIndex()))
46 err := stack.switchDictionary(src, dst)
47 if err != nil {
48 return fmt.Errorf("couldn't switch stack dictionary: %w", err)
49 }
50
51 idx, err := SetStack(dst.StackTable(), stack)
52 if err != nil {
53 return fmt.Errorf("couldn't set stack: %w", err)
54 }
55 ms.SetStackIndex(idx)
56 }
57
58 return nil
59 }