Android performance test fluency test




The fluency test is simply Android page drawing. The Android system refreshes the interface every second at 60hz, which is about every 16ms. However, in the process of using the APP, we often see that the page is stuck, or the frame is dropped. That is to say, the time difference between the two pages drawn at this moment may exceed 0.1S (the human eye vision remains 0.1S). In general, it is the

principle .

Before determining the measurement indicators, let's talk about the UI update mechanism of Android.

During the Android version update process, it was found that Google added a Project Butter in Jelly Bean to solve one of the problems that seriously affected Android's reputation, "poor UI fluency". And Project Butter mainly introduces three core elements: VSYNC (vertical synchronization), Triple Buffer and Choreographer.

VSync is the abbreviation of Vertical Synchronization (Vertical Synchronization), which is a technology that has been widely used on PCs for a long time. In Android 4.1 (JB), the VSync mechanism has been introduced. The processing time of both CPU and GPU is less than one VSync interval, which is 16.6ms. If every interval is drawn, the current FPS is 60 frames.

The VSync mechanism is like playing a cartoon (60 frames/s). The screen will be played every time. Sometimes someone is lazy and the machine is broken, and the playback speed will decrease. We call this playback speed fluency.

From FPS & Dropped Frames to Fluency

In fact, in many Android apps, there are few scenes that need to be drawn continuously, and many times the pages are static. That is to say, this situation will occur. Although not all of the 60 Loops of VSync in 1s are doing drawing work, the FPS will be relatively low, but it does not mean that the program is not smooth at this time (for example, if I leave the App unmoved, The measured FPS is 1). Therefore, a lower FPS does not mean that the current App is not smooth on the UI, and how many times the VSync Loop has been run within 1s can better indicate the smoothness of the current App. Therefore, the following two indicators can better represent whether the current App is in a smooth state than FPS. Similarly, these two indicators can better quantify the degree of App freeze:

1) Lost frame (SF: Skipped Frame): As shown in Figure 2 above, the work should be completed in 16.6ms, but it was not completed due to various reasons, accounting for the last n A time of 16.6ms is equivalent to losing n frames.

2) Fluency (SM: SMoothness): Compared with dropped frames, the number of times the Loop runs within 1s in the VSync mechanism.

Compared with frame loss, there are 60 loops within 1s because the working time exceeds 16.6ms (frame loss) for some times, so the loop cannot run 60 times (theoretical maximum).

When the fluency is smaller, it means that the current program is more stuck.

How to get fluency (SM: SMoothness)

Continuing with the above conclusion, it would be nice to record the number if it is notified before each Loop runs under such a mechanism.

Luckily, we found a Choreographer object in the new Android set of mechanics. According to Google's official API document description, it is used to coordinate animations, input and drawing timing, and each Loop shares a Choreographer object.

Conclusion

Through the above principle analysis, it can be concluded that:

1) After Android 4.1 introduced the VSync mechanism, you can know the current App's highest drawing capability through its Loop.

Fixed to execute once every 16.6ms (this value is a static variable, which will be different depending on the system version, the current test version is 16.6ms, the highest refresh frame rate is controlled within 60FPS);

if there is no above event It will also run such a Loop; how many times

this Loop runs within 1s, it can indicate the highest ability of the current App to draw, that is, the degree of Android App stuck;

If it exceeds 16.6ms, then divide the time more than 16.6ms by 16.6ms, which is the dropped frame (SF: Skipped Frame) of the current App.

2) In the callback FrameCallback of Choreographer, the fluency of the current App can be expressed in seconds, that is, the fluency SM (SMoothness).

In this way, the fluency of the current App can be observed inside the App. And print the traceView where the frame is dropped, you can know the approximate reason and the approximate location of the dropped frame. Locate code issues.

TestBird

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326192318&siteId=291194637