Debian Codegraph @

pdata/pprofile/locations.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 "errors"
8 "math"
9 )
10
11 // FromLocationIndices builds a slice containing all the locations of a Stack.
12 // Updates made to the returned map will not be applied back to the Stack.
13 func FromLocationIndices(table LocationSlice, record Stack) LocationSlice {
14 m := NewLocationSlice()
15 m.EnsureCapacity(record.LocationIndices().Len())
16
17 for _, idx := range record.LocationIndices().All() {
18 l := table.At(int(idx))
19 l.CopyTo(m.AppendEmpty())
20 }
21
22 return m
23 }
24
25 var errTooManyLocationTableEntries = errors.New("too many entries in LocationTable")
26
27 // SetLocation updates a LocationTable, adding or providing a value and returns
28 // its index.
29 func SetLocation(table LocationSlice, loc Location) (int32, error) {
30 for j, a := range table.All() {
31 if a.Equal(loc) {
32 if j > math.MaxInt32 {
33 return 0, errTooManyLocationTableEntries
34 }
35 return int32(j), nil
36 }
37 }
38
39 if table.Len() >= math.MaxInt32 {
40 return 0, errTooManyLocationTableEntries
41 }
42
43 loc.CopyTo(table.AppendEmpty())
44 return int32(table.Len() - 1), nil
45 }