Debian Codegraph @

pdata/pprofile/profiles.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 // MarkReadOnly marks the ResourceProfiles as shared so that no further modifications can be done on it.
9 func (ms Profiles) MarkReadOnly() {
10 ms.getState().MarkReadOnly()
11 }
12
13 // IsReadOnly returns true if this ResourceProfiles instance is read-only.
14 func (ms Profiles) IsReadOnly() bool {
15 return ms.getState().IsReadOnly()
16 }
17
18 // SampleCount calculates the total number of samples.
19 func (ms Profiles) SampleCount() int {
20 sampleCount := 0
21 rps := ms.ResourceProfiles()
22 for i := 0; i < rps.Len(); i++ {
23 rp := rps.At(i)
24 sps := rp.ScopeProfiles()
25 for j := 0; j < sps.Len(); j++ {
26 pcs := sps.At(j).Profiles()
27 for k := 0; k < pcs.Len(); k++ {
28 sampleCount += pcs.At(k).Samples().Len()
29 }
30 }
31 }
32 return sampleCount
33 }
34
35 // switchDictionary updates the Profiles, switching its indices from one
36 // dictionary to another.
37 func (ms Profiles) switchDictionary(src, dst ProfilesDictionary) error {
38 for i, v := range ms.ResourceProfiles().All() {
39 err := v.switchDictionary(src, dst)
40 if err != nil {
41 return fmt.Errorf("error switching dictionary for resource profile %d: %w", i, err)
42 }
43 }
44
45 return nil
46 }