Use onCreate invocation to denote Activity init start time #820
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
In production, we are seeing a small minority of cases where there is a big gap between when onActivityPreCreated was invoked and when onActivityStart() was invoked. This could be a case of these being two separate activities or instances, or there are cases when the activity creation and starting stage can be paused.
In order to improve the trace and diagnose what's really going on, I changed the trace to use the onCreate time rather than the preCreate time, which is how it works on Android 9 or earlier, as preCreate is not a thing on those API versions. We also explicitly log the pre-create and post-create times as attributes for further debugging if this doesn't end up addressing the problem.
As well as the fix, I tweaked the implementation of the trace logging component (AppStartupTraceEmitter) so it's more streamlined, logs the name of the activity being displayed, removed the emb- prefix on attributes, and extracted the public interface into an interface so i can more easily test the StartupTracker by faking that.
In additional, I added more tests to verify the startup trace being logged properly as well as the
StartupTracker
consuming lifecycle events properly. I couldn't add test to verify the render due to the limitations of Roboletric, so I've left that alone for now. I've spent way too much time on this already....Testing
Updated Roboletric to the latest stable version so I can test with U as well as added the modified the appropriate tests.