-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
introduce pprofile.AddAttribute helper #12390
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #12390 +/- ##
==========================================
- Coverage 92.00% 91.98% -0.03%
==========================================
Files 469 469
Lines 25301 25328 +27
==========================================
+ Hits 23279 23297 +18
- Misses 1614 1620 +6
- Partials 408 411 +3 ☔ View full report in Codecov by Sentry. |
@bogdandrutu I'm happy to hear your input on improvements here, especially with the loop through all attributes issue, and the use of |
Co-authored-by: Tim Rühsen <tim.ruehsen@gmx.de>
Co-authored-by: Tim Rühsen <tim.ruehsen@gmx.de>
// AddAttribute updates an AttributeTable and a record's AttributeIndices to | ||
// add a new attribute. | ||
// The record can by any struct that implements an `AttributeIndices` method. | ||
func AddAttribute(table AttributeTableSlice, record attributable, key string, value any) error { |
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.
How come the attributable
type is not an exported type (of some package)?
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.
attributable is there to allow the behavior on any of the generated types that have attribute indices.
Location, Mapping, Sample.
Folks will only ever need to manipulate the generated struct. They don't need the interface.
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Description
This introduces the
pprofile.AddAttribute
helper method so profile extensions can modify attributes.Closes #12206
Those benchmarks kind of have an N+1 issue, where the method will take longer the more attributes there are.
However, since the attribute table is a map, we can't go around with looping through it.
I also had to use
FromRaw
andAsRaw
in there, to properly handleany
values.This currently doesn't support removing entries. But doing so would also have a non-trivial performance impact, since we'd have to loop through the
AttributeIndices
slice.