| 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 Location |
| 9 |
func (ms Location) Equal(val Location) bool { |
| 10 |
return ms.MappingIndex() == val.MappingIndex() && |
| 11 |
ms.Address() == val.Address() && |
| 12 |
ms.AttributeIndices().Equal(val.AttributeIndices()) && |
| 13 |
ms.Lines().Equal(val.Lines()) |
| 14 |
} |
| 15 |
|
| 16 |
// switchDictionary updates the Location, switching its indices from one |
| 17 |
// dictionary to another. |
| 18 |
func (ms Location) switchDictionary(src, dst ProfilesDictionary) error { |
| 19 |
if ms.MappingIndex() > 0 { |
| 20 |
if src.MappingTable().Len() < int(ms.MappingIndex()) { |
| 21 |
return fmt.Errorf("invalid mapping index %d", ms.MappingIndex()) |
| 22 |
} |
| 23 |
|
| 24 |
mapping := src.MappingTable().At(int(ms.MappingIndex())) |
| 25 |
err := mapping.switchDictionary(src, dst) |
| 26 |
if err != nil { |
| 27 |
return fmt.Errorf("couldn't switch dictionary for mapping: %w", err) |
| 28 |
} |
| 29 |
idx, err := SetMapping(dst.MappingTable(), mapping) |
| 30 |
if err != nil { |
| 31 |
return fmt.Errorf("couldn't set mapping: %w", err) |
| 32 |
} |
| 33 |
ms.SetMappingIndex(idx) |
| 34 |
} |
| 35 |
|
| 36 |
for i, v := range ms.AttributeIndices().All() { |
| 37 |
if src.AttributeTable().Len() < int(v) { |
| 38 |
return fmt.Errorf("invalid attribute index %d", v) |
| 39 |
} |
| 40 |
|
| 41 |
attr := src.AttributeTable().At(int(v)) |
| 42 |
err := attr.switchDictionary(src, dst) |
| 43 |
if err != nil { |
| 44 |
return fmt.Errorf("couldn't switch dictionary for attribute %d: %w", i, err) |
| 45 |
} |
| 46 |
idx, err := SetAttribute(dst.AttributeTable(), attr) |
| 47 |
if err != nil { |
| 48 |
return fmt.Errorf("couldn't set attribute %d: %w", i, err) |
| 49 |
} |
| 50 |
ms.AttributeIndices().SetAt(i, idx) |
| 51 |
} |
| 52 |
|
| 53 |
for i, v := range ms.Lines().All() { |
| 54 |
err := v.switchDictionary(src, dst) |
| 55 |
if err != nil { |
| 56 |
return fmt.Errorf("couldn't switch dictionary for line %d: %w", i, err) |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return nil |
| 61 |
} |