| 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 |
var errTooManyStackTableEntries = errors.New("too many entries in StackTable") |
| 12 |
|
| 13 |
// SetStack updates a StackSlice, adding or providing a stack and returns its |
| 14 |
// index. |
| 15 |
func SetStack(table StackSlice, st Stack) (int32, error) { |
| 16 |
for j, l := range table.All() { |
| 17 |
if l.Equal(st) { |
| 18 |
if j > math.MaxInt32 { |
| 19 |
return 0, errTooManyStackTableEntries |
| 20 |
} |
| 21 |
return int32(j), nil |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
if table.Len() >= math.MaxInt32 { |
| 26 |
return 0, errTooManyStackTableEntries |
| 27 |
} |
| 28 |
|
| 29 |
st.CopyTo(table.AppendEmpty()) |
| 30 |
return int32(table.Len() - 1), nil |
| 31 |
} |