Skip to content

FirebaseExtended/codelab-measure-android-view-performance

Repository files navigation

Measuring Load time and Screen Rendering with Firebase Performance

This repo contains the source code to be used for the Codelab for Google I/O 2021 and Firebase Summit 2021.

Supported Features

Activity/Fragment load time

This is measured in 2 phases.

In the first phase we measure the time when the view tree is about to be drawn. This is done by registering a callback to ViewTreeObserver.OnDrawListener. Getting this callback for the very first time (first frame) means that the complete UI (including all views in the view hierarchy) have been measured, laid out and given a frame. The drawing operation happens immediately after this callback.

In the second phase we measure the time when that first frame view is completely drawn. This is done by posting a message to the front of MessageQueue of the Looper associated with the Main/UI thread (reference).

Note: This is how Android framework measures the app startup time i.e by measuring the time from creating the app object until when the first frame completely loads and drawn on the screen (reference).

Fragment Screen Rendering (Slow/Frozen frames)

FirebasePerformance automatically records Screen Rendering data for Activities (reference) however, it does not record this information for Fragments. This is because the FrameMetricsAggregator API records the duration of rendering for an entire window and not a part of window.

We can however record those metrics for the duration when the Fragment is active. This is done by start recording the frames as soon as the Fragment is attached to the screen and stop recording as soon as the Fragment is detached.

The core logic for Slow/Frozen frames is copied from Fireperf Source Code. This also means we create the trace name with SCREEN_TRACE_PREFIX and attach frame metrics so as to show the screen rendering information for the Fragment on the Firebase Console.

Note: If Fragment is covering only a part of the Screen than the reported metric will be skewed as it's impossible to know (from that API) what part of the screen contributes to those results.

Credits

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages