Debian Codegraph @

pdata/pprofile/profile.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 (
7 "fmt"
8
9 "go.opentelemetry.io/collector/pdata/pcommon"
10 )
11
12 // switchDictionary updates the Profile, switching its indices from one
13 // dictionary to another.
14 func (ms Profile) switchDictionary(src, dst ProfilesDictionary) error {
15 for i, v := range ms.AttributeIndices().All() {
16 if src.AttributeTable().Len() < int(v) {
17 return fmt.Errorf("invalid attribute index %d", v)
18 }
19
20 attr := src.AttributeTable().At(int(v))
21 err := attr.switchDictionary(src, dst)
22 if err != nil {
23 return fmt.Errorf("couldn't switch dictionary for attribute %d: %w", i, err)
24 }
25 idx, err := SetAttribute(dst.AttributeTable(), attr)
26 if err != nil {
27 return fmt.Errorf("couldn't set attribute %d: %w", i, err)
28 }
29 ms.AttributeIndices().SetAt(i, idx)
30 }
31
32 for i, v := range ms.Samples().All() {
33 err := v.switchDictionary(src, dst)
34 if err != nil {
35 return fmt.Errorf("error switching dictionary for sample %d: %w", i, err)
36 }
37 }
38
39 err := ms.PeriodType().switchDictionary(src, dst)
40 if err != nil {
41 return fmt.Errorf("error switching dictionary for period type: %w", err)
42 }
43 err = ms.SampleType().switchDictionary(src, dst)
44 if err != nil {
45 return fmt.Errorf("error switching dictionary for sample type: %w", err)
46 }
47
48 return nil
49 }
50
51 // Duration returns the duration associated with this Profile.
52 //
53 // Deprecated: Use Profile.DurationNano instead.
54 func (ms Profile) Duration() pcommon.Timestamp {
55 return pcommon.Timestamp(0)
56 }
57
58 // SetDuration replaces the duration associated with this Profile.
59 //
60 // Deprecated: Use Profile.SetDurationNano instead.
61 func (ms Profile) SetDuration(_ pcommon.Timestamp) {
62 }