1.gpu rendering mode analysis
Open developer mode, select gpu rendering mode analysis. Can be seen on the screen bars, each frame representative of the time-consuming, time-consuming different colors represent different stages in the drawing, there is a problem which can judge stage. Green line represents 16.67ms transverse baseline, only takes a long time before the rain 16.67ms frame loss will not happen.
2.adb shell dumpsys gfxinfo <PACKAGE_NAME>
Command line to run adb shell dumpsys gfxinfo, statistical data applications will open in return, but only for each frame the total statistics do not include a specific time-consuming each stage, while the total number of frames will be lost, dropped frames ratio, time-consuming frame line 90, line 95, 99 lines.
Suffix added framestats Processed it is possible to obtain a latest stage 120, the first row may be divided with reference to a specific output profileData including Flags, IntendedVsync, Vsync, OldestInputEvent etc., https://developer.android.com / training / testing / performance # fs -data-format can be seen by the specific contents of the corresponding android official website.
Adding the suffix can be reset in the next survey results reset to reset to a point in time, before the data are cleared.
3.Choreographer.postFrameCallBack
Choreographer是android UI线程绘制的节拍器,是一个threadlocal变量,UI线程里的Choreographer可以认为是一个单例,接收vsync信号进行界面的渲染,可以通过对choreographer设置FrameCallback回调获得每一帧的与上一帧的时长,但不含每一个阶段的时间,并且界面不发生改变时vsync信号也会传递,会导致获得的FPS偏高,本文介绍的其他三种方法则没有这个确定。
4.Window.OnFrameMetricsAvailableListener
OnFrameMetricsAvailableListener是Android在api 24版本加入的强大新功能,通过设置OnFrameMetricsAvailableListener回调可以获得每一帧每一个阶段的耗时,以及总的耗时,并且可以获得当前帧是否是第一次绘制,android官方认为第一帧由于存在大量初始化的代码,其第一帧的数据不应记在FPS内。