Mobile Development 6 min read

Android Frame Drop Detection and Monitoring Principles

The article explains Android’s frame‑drop detection and monitoring principles, covering refresh rate, Vsync, Choreographer and FrameInfo mechanisms, how lag is perceived, methods to calculate and retrieve dropped frames, and best practices such as avoiding heavy main‑thread work to ensure smooth UI performance.

OPPO Kernel Craftsman
OPPO Kernel Craftsman
OPPO Kernel Craftsman
Android Frame Drop Detection and Monitoring Principles

This article discusses frame drop detection and monitoring principles in Android, focusing on user-perceived lag scenarios such as ANR, slow app startup, unstable frame rates in games, slow video loading, and noticeable frame drops during scrolling. The article specifically addresses UI operation type lag from a frame drop perspective.

Before discussing lag, the article introduces several key concepts: Refresh Rate (screen refresh speed, typically 60Hz, 90Hz common, with OPPO Find X2 series supporting 120Hz), Frame Rate (frames per second the system can render), and Vsync mechanism (synchronizes screen refresh rate and frame rate to avoid screen tearing).

The article explains when users perceive lag: when frame rate exceeds screen refresh rate causing tearing (multiple frames displayed on the same frame buffer), or when screen refresh rate exceeds frame rate causing choppiness unless the frame rate is a stable fraction of the refresh rate (e.g., 1/2).

The article then covers Android's frame drop detection methods, focusing on Choreographer and FrameInfo mechanisms. Choreographer coordinates with Vsync to ensure stable frame rendering output, acting as an intermediary between input, animation, and traversal callbacks while recording frame drop situations.

Key aspects of Choreographer include: requesting Vsync → receiving Vsync → requesting Vsync → receiving Vsync (continuous cycle), maintaining a CallbackQueue for components like ViewRootImpl and ValueAnimator, and triggering Vsync requests when component changes occur.

The doFrame function performs three main tasks: calculating frame drops, recording frame drawing information, and executing five callbacks (CALLBACK_INPUT, CALLBACK_ANIMATION, CALLBACK_INSETS_ANIMATION, CALLBACK_TRAVERSAL, CALLBACK_COMMIT). Frame drop calculation compares start_time (intendedFrameTime) with end_time (actual doFrame execution time), with the difference representing Vsync processing delay.

FrameInfo records frame drawing information, with each key node's drawing time recorded during doFrame execution. Android provides gfxinfo to retrieve frame drop information via adb shell dumpsys gfxinfo packageName framestats, which records frame time intervals in the JankTracker.cpp file.

The article also discusses monitoring implementation methods: using Choreographer's FrameCallback interface, utilizing FrameInfo for monitoring, and leveraging Choreographer's internal frame drop calculation logic with the SKIPPED_FRAME_WARNING_LIMIT default value of 30.

Finally, the article summarizes key points: avoid time-consuming operations on the main thread to prevent exceeding Vsync cycles, and notes that FrameInfo recording provides more comprehensive coverage than Choreographer's doFrame measurement.

mobile developmentAndroidperformance monitoringChoreographerui-optimizationVSyncframe drop
OPPO Kernel Craftsman
Written by

OPPO Kernel Craftsman

Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.