-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor output #1778
Refactor output #1778
Conversation
need to stare at it a bit more but looks good |
looks good. @andreasgerstmayr, are you interested in giving this a go? I think you're the most active user of this. |
looks good, I'll try it out next week. |
I tested it today, works fine! One thing I noticed is that now, instead of sending the output direct to the output stream fwiw, I didn't notice an impact for my application. I don't know if this might become an issue with very big maps, what do you think @fbs? If we continue on this route (building data structures before printing), we could also consider vendoring a JSON library in the future? |
Thanks for the review @andreasgerstmayr! Good point about the string efficiency. I don't expect bpftrace users to create maps so huge that this would actually matter, so I prefer the elegant solution rather than a highly optimized one. But if someone thinks that we should address the issue, it shouldn't be a problem to re-implement this. I'm not sure how efficient modern compilers are in terms of string concatenation, but we could probably pre-reserve enough memory in |
I'm fine with both ways, I'll leave it to @fbs if the PR should be updated regarding the string allocations or not. |
Would be nice to have but not blocking. Lets just get this in :) |
@viktormalik can you fix the changelog iissue? |
Previously static methods of the BPFtrace class can be used from other classes this way.
- move the method map_value_to_str from BPFtrace to Output - add handling of tuples - this allows to simplify printing of values from the JsonOutput class - JSON printing of tuples containing aggregate types (structs or arrays) is now working
There was a lot of code duplicated between TextOutput and JsonOutput. This commit moves the common code for printing maps into the parent Output class and leaves only the different parts to the extending classes.
1ae9f7c
to
40db251
Compare
Fixed, ready for rebase. Should I open an issue for the string allocation optmization? |
Following the discussion in #1705 (comment), I tried to do some refactoring of the
Output
class. Main changes in this PR are:Output
TextOutput
andJsonOutput
by moving it into the baseOutput
classOutput
now defines an interface that all output classes must defineOutput
implements some methods that are likely to behave the same between all output formattersThere's surely room for more improvement, so feel free to suggest more changes that could be done here.
Checklist
docs/reference_guide.md
CHANGELOG.md