Giter Club home page Giter Club logo

codelab-measure-android-view-performance's Introduction

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

codelab-measure-android-view-performance's People

Contributors

jeremyjiang-dev avatar ramanpreetsinghkhinda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.