Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions profcheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package profcheck
import (
"errors"
"fmt"
"slices"

profiles "go.opentelemetry.io/proto/otlp/profiles/v1development"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -212,7 +213,16 @@ func (c ConformanceChecker) checkMappingTable(mappingTable []*profiles.Mapping,
if err := checkZeroVal(mappingTable); err != nil {
errs = errors.Join(errs, err)
}
for idx, m := range mappingTable {

type uniqMapping struct {
filenameStrIdx int32
attrIdxs []int32
memStart uint64
memLimit uint64
}
var uniqMappings []uniqMapping

for idx, m := range mappingTable[1:] {
if err := c.checkIndex(len(dict.StringTable), m.FilenameStrindex); err != nil {
errs = errors.Join(errs, prefixErrorf(err, "[%d].filename_strindex", idx))
}
Expand All @@ -222,8 +232,27 @@ func (c ConformanceChecker) checkMappingTable(mappingTable []*profiles.Mapping,
if !(m.MemoryStart == 0 && m.MemoryLimit == 0) && !(m.MemoryStart < m.MemoryLimit) {
errs = errors.Join(errs, fmt.Errorf("[%d]: memory_start=%016x, memory_limit=%016x: must be both zero or start < limit", idx, m.MemoryStart, m.MemoryLimit))
}
if c.CheckDictionaryDuplicates {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this style of duplicate entry check is fine for everyone, I can apply it to the other tables as well.

newMapping := uniqMapping{
filenameStrIdx: m.FilenameStrindex,
attrIdxs: m.AttributeIndices,
memStart: m.MemoryStart,
memLimit: m.MemoryLimit,
Comment thread
florianl marked this conversation as resolved.
}
if slices.ContainsFunc(uniqMappings, func(e uniqMapping) bool {
if slices.Equal(newMapping.attrIdxs, e.attrIdxs) {
return true
}
return newMapping.filenameStrIdx == e.filenameStrIdx ||
newMapping.memStart == e.memStart ||
newMapping.memLimit == e.memLimit
}) {
errs = errors.Join(errs, fmt.Errorf("duplicate mapping at index %d: %v", idx, m))
continue
}
uniqMappings = append(uniqMappings, newMapping)
}
}
// TODO: Add optional uniqueness check.
// TODO: Add optional unreferenced entries check.
return errs
}
Expand Down
Loading