測試背景:
APP 在測試機運行一段時間後出現手機發燙、卡頓、高 CPU 佔有率的現象。將應用切入後臺進行 CPU 數據的監測,結果顯示,即使應用不進行任何操作,應用的 CPU 佔有率都會持續的增長
卡頓的原因大致有:佈局性能不好,內存垃圾回收機制(GC)--內存抖動(大量的內存在短期內佔用和釋放),CPU佔用過高,硬件加速,過度繪製
參考網址:
工具使用次序:
首先使用GPU profile或使用adb shell dumpsys gfxinfo得到的速度,如果界面卡頓這些值應該大於16.67ms,這時候就需要使用traceview或systrace抓到詳細的信息給開發提供。
應用profile trace
步驟:
如果出現<60FPS的情況,用docs/tools/debugging/debugging-tracing.html
adb shell am profile start <package> /data/local/tmp/xxx.trace #在測試之前啓用
測試。。。。
adb shell am profile stop <package>測試之後立即執行,儘量讓start 和stop短,因爲越長越難分析。
adb pull /data/local/tmp/xxx.trace . #導出trace後用traceview查看。
使用systrace進行
Tracing on Android 4.3 and higher
The general syntax for running Systrace from the command line is as follows.
$ python systrace.py [options] [category1] [category2] ... [categoryN]
Here is an example execution run that sets trace tags and generates a trace from a connected device.
$ cd ''android-sdk''/platform-tools/systrace
$ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm
To set trace tags for Systrace using the device user interface:
On the device connected for tracing, navigate to: Settings > Developer options > Monitoring > Enable traces.
Select the categories of processes to be traced and click OK.
options:
gfx - Graphics
input - Input
view - View System
webview - WebView
wm - Window Manager
am - Activity Manager
sm - Sync Manager
audio - Audio
video - Video
camera - Camera
hal - Hardware Modules
app - Application
res - Resource Loading
dalvik - Dalvik VM
rs - RenderScript
bionic - Bionic C Library
power - Power Management
sched - CPU Scheduling
freq - CPU Frequency
idle - CPU Idle
load - CPU Load
reference:
應用幀率FPS測量
Android應用幀率FPS是衡量應用流暢度的一個非常重要的指標,可以根據FPS對應用做一些優化,那麼在開發過程中如何來測試我們的應用的FPS呢?
準備工具:Eclipse + Android測試終端
測試步驟:
1、在設置裏打開GPU呈現模式分析。點擊Android設備的“設置”->"開發者選項",然後勾選“GPU呈現模式分析”(各終端可能不一樣,重點是就算adb shell dumpsys gfxinfo)。
2、重啓我們的應用。啓動應用以後,在應用的頁面上做滑動。
3、打開命令行,在命令行輸入:adb shell dumpsys gfxinfo "你自己的應用名字" > f:\fps.txt
結果分析:
1、打開生成的fps.txt,找到Profile data in ms這部分數據。
2、爲了看得更直接,我們可以把數據放到Excel中,然後以圖表的形式進行查看。
3、從圖中可以看出來,我這個應用的流暢度是很低的,正常情況下幀率應該在16ms左右,如果1秒60幀的話,而且Execute時間太長!所以是需要進行優化的
測試背景:
APP 在測試機運行一段時間後出現手機發燙、卡頓、高 CPU 佔有率的現象。將應用切入後臺進行 CPU 數據的監測,結果顯示,即使應用不進行任何操作,應用的 CPU 佔有率都會持續的增長
參考網址:
應用profile trace
步驟:
如果出現<60FPS的情況,用docs/tools/debugging/debugging-tracing.html
adb shell am profile start <package> /data/local/tmp/xxx.trace #在測試之前啓用
測試。。。。
adb shell am profile stop <package>測試之後立即執行,儘量讓start 和stop短,因爲越長越難分析。
adb pull /data/local/tmp/xxx.trace . #導出trace後用traceview查看。
使用systrace進行
file:///home/alex/Android/Sdk/docs/tools/debugging/systrace.html
Tracing on Android 4.3 and higher
The general syntax for running Systrace from the command line is as follows.
$ python systrace.py [options] [category1] [category2] ... [categoryN]
Here is an example execution run that sets trace tags and generates a trace from a connected device.
$ cd ''android-sdk''/platform-tools/systrace
$ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm
To set trace tags for Systrace using the device user interface:
On the device connected for tracing, navigate to: Settings > Developer options > Monitoring > Enable traces.
Select the categories of processes to be traced and click OK.
options:
gfx - Graphics
input - Input
view - View System
webview - WebView
wm - Window Manager
am - Activity Manager
sm - Sync Manager
audio - Audio
video - Video
camera - Camera
hal - Hardware Modules
app - Application
res - Resource Loading
dalvik - Dalvik VM
rs - RenderScript
bionic - Bionic C Library
power - Power Management
sched - CPU Scheduling
freq - CPU Frequency
idle - CPU Idle
load - CPU Load
reference:
應用幀率FPS測量
Android應用幀率FPS是衡量應用流暢度的一個非常重要的指標,可以根據FPS對應用做一些優化,那麼在開發過程中如何來測試我們的應用的FPS呢?
準備工具:Eclipse + Android測試終端
測試步驟:
1、在設置裏打開GPU呈現模式分析。點擊Android設備的“設置”->"開發者選項",然後勾選“GPU呈現模式分析”(各終端可能不一樣,重點是就算adb shell dumpsys gfxinfo)。
2、重啓我們的應用。啓動應用以後,在應用的頁面上做滑動。
3、打開命令行,在命令行輸入:adb shell dumpsys gfxinfo "你自己的應用名字" > f:\fps.txt
解析:
adb shell dumpsys gfxinfo packageName | awk '/Execute/,/hierarchy/{if(i>1)print x;x=$0;i++}' | sed /^[[:space:]]*$/d|awk '{if(length($0)==16print $1,$2,$3}'
結果分析:
1、打開生成的fps.txt,找到Profile data in ms這部分數據。
2、爲了看得更直接,我們可以把數據放到Excel中,然後以圖表的形式進行查看。
3、從圖中可以看出來,我這個應用的流暢度是很低的,正常情況下幀率應該在16ms左右,如果1秒60幀的話,而且Execute時間太長!所以是需要進行優化的
60fps<==>per frame 《16ms