[PLAT-7804] Improve crash report writing performance with buffered output#1281
Merged
Conversation
kstenerud
suggested changes
Jan 13, 2022
kstenerud
left a comment
Contributor
There was a problem hiding this comment.
I think we need some isolated tests of BSG_KSFile to check all edge cases...
Contributor
|
Allocations don't have to all happen on the stack. In a crashed context there will only be one thread that can use it at a time, so a globally pre-allocated buffer will suffice. On a recrash, you just reinit the buffering mechanism since the previous crash handler has been stopped in its tracks. |
0949b2d to
099c5a7
Compare
Contributor
Author
Added a unit test that covers all the non-error code. |
kstenerud
approved these changes
Jan 13, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Improve the performance of writing crash reports, to reduce the likelihood of apps being terminated (by watchdog or user) before finishing.
Design
Use write buffers to reduce the number of calls to
write().malloc()'d at run-time due to the constrained crash-time environment. Thoughts on the safety of this are welcome - perhaps static allocation should be used instead at the expense of thread safety (which is not something we support in the crash handler.)Changeset
BSG_KSFile.c.BSG_KSCrashReport.cto use buffered output.BSG_KSCrashState.mto use buffered output.Testing
Tested by updating unit tests
BSG_KSCrashReportTestsandKSCrashState_Tests.Also verified by manually inspecting crash report files and running full E2E suite on CI. Bugs in file writing would manifest as unreported crashes.
The performance unit test case shows improvements of 40-60% depending on the device.
Profiling shows that around 95% of
bsg_kscrashreport_writeStandardReport()'s time is now spent inbsg_symbolicate().