Debian Codegraph @

pdata/pprofile/mapping.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 // Equal checks equality with another Mapping
9 func (ms Mapping) Equal(val Mapping) bool {
10 return ms.MemoryStart() == val.MemoryStart() &&
11 ms.MemoryLimit() == val.MemoryLimit() &&
12 ms.FileOffset() == val.FileOffset() &&
13 ms.FilenameStrindex() == val.FilenameStrindex() &&
14 ms.AttributeIndices().Equal(val.AttributeIndices())
15 }
16
17 // switchDictionary updates the Mapping, switching its indices from one
18 // dictionary to another.
19 func (ms Mapping) switchDictionary(src, dst ProfilesDictionary) error {
20 if ms.FilenameStrindex() > 0 {
21 if src.StringTable().Len() < int(ms.FilenameStrindex()) {
22 return fmt.Errorf("invalid filename index %d", ms.FilenameStrindex())
23 }
24
25 idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.FilenameStrindex())))
26 if err != nil {
27 return fmt.Errorf("couldn't set filename: %w", err)
28 }
29 ms.SetFilenameStrindex(idx)
30 }
31
32 for i, v := range ms.AttributeIndices().All() {
33 if src.AttributeTable().Len() < int(v) {
34 return fmt.Errorf("invalid attribute index %d", v)
35 }
36
37 attr := src.AttributeTable().At(int(v))
38 err := attr.switchDictionary(src, dst)
39 if err != nil {
40 return fmt.Errorf("couldn't switch dictionary for attribute %d: %w", i, err)
41 }
42 idx, err := SetAttribute(dst.AttributeTable(), attr)
43 if err != nil {
44 return fmt.Errorf("couldn't set attribute %d: %w", i, err)
45 }
46 ms.AttributeIndices().SetAt(i, idx)
47 }
48
49 return nil
50 }