-
Notifications
You must be signed in to change notification settings - Fork 8
profcheck: implement duplicate mappings check #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package profcheck | |
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "slices" | ||
|
|
||
| profiles "go.opentelemetry.io/proto/otlp/profiles/v1development" | ||
| "google.golang.org/protobuf/proto" | ||
|
|
@@ -212,7 +213,17 @@ 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 | ||
| fileOffset 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)) | ||
| } | ||
|
|
@@ -222,8 +233,29 @@ 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 { | ||
| newMapping := uniqMapping{ | ||
| filenameStrIdx: m.FilenameStrindex, | ||
| attrIdxs: m.AttributeIndices, | ||
| memStart: m.MemoryStart, | ||
| memLimit: m.MemoryLimit, | ||
|
florianl marked this conversation as resolved.
|
||
| fileOffset: m.FileOffset, | ||
| } | ||
| if slices.ContainsFunc(uniqMappings, func(e uniqMapping) bool { | ||
| slices.Sort(newMapping.attrIdxs) | ||
| slices.Sort(e.attrIdxs) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're doing a lot of redundant operations here (like iterating Can't we switch
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunatly it is not possible to use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I mentioned switching |
||
| return newMapping.filenameStrIdx == e.filenameStrIdx && | ||
| slices.Equal(newMapping.attrIdxs, e.attrIdxs) && | ||
|
florianl marked this conversation as resolved.
|
||
| newMapping.memStart == e.memStart && | ||
| newMapping.memLimit == e.memLimit && | ||
| newMapping.fileOffset == e.fileOffset | ||
| }) { | ||
| 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 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.