1. input
input text <string>
輸入字串,可以不使用軟鍵盤,更方便調試(包括寫指令碼測試)
input keyevent <event_code>
輸入按鍵事件,支援全鍵盤按鍵,可以在沒有輸入裝置時,作業系統。按鍵事件可以參考源檔案:KeyEvent.java
e.g:
input keyevent 82 // unlock
input keyevent 1 // left softkey
input keyevent 2 // right softkey
input keyevent 3 // back idle
input keyevent 4 // back key
JellyBean上,可以支援更多的功能:
input keyevent <key codenumber or name>
Keyevent可以用名字表示,如:
input keyevent MENU (JellyBean)
input tap <x> <y>
可以發送一個點擊事件。
input swipe <x1> <y1> <x2><y2>
可以發送一個滑動事件,如往右滑動:
input swipe 100 200 300 200
2. screencap
截屏工具
請求SurfaceFlinger重新renderSurface
>>surfaceFlinger通過openGL畫到FBO中
>> 沒有走hwcomposer及我們的DE最終顯示
如果這個和最終螢幕顯示可能不一致:
>> SurfaceFlinger有問題(framebuffer或hwcomposer)
>> 有overlay
>>我們的DE有兩層, graphic(Android UI) 和overlay (video/camera的顯示),目前只針對前者
截取framebuffer,可以通過sys檔案介面實現
>> Cat/dev/graphics/fb0
使用方式:
usage: screencap [-hp] [FILENAME]
-h: this message
-p: save the file as a png.
If FILENAME ends with .png it will be saved asa png.
If FILENAME is not given, the results will beprinted to stdout.
#adb shell screencap –p /sdcard/screen1.png
#adb pull /sdcard/screen1.png .
3. monkey
Monkey是裝置上的可執行程式,產生隨機數如事件
>> Keyevent
>> Touch event
>> Guesture
>> System events
開發階段作為壓力測試使用
客戶定製階段可部分作為穩定性驗證
可通過指令碼實現一定的測試方法
命令格式
>> usage: monkey[options] COUNT
參數詳解
>> Basicconfiguration options, such as setting the number of events toattempt.
>> Operationalconstraints, such as restricting the test to a singlepackage.
>> Event types andfrequencies.
>> Debugging options.
>>https://developer.android.com/tools/help/monkey.html
常用命令:
monkey 100 (基本命令)
monkey --ignore-crashes --ignore-timeouts99999 (無特定目的的壓力測試)
monkey –p com.android.browser –pcom.android.launcher –v –v 999999 (僅測試lancher和browser,測試是輸出最多的trace資訊)
4. am
Android可以支援從命令列控制android的啟動行為
在項目/硬體帶起的初始階段,很有協助
usage: am [subcommand] [options]
e.g:
啟動music:
am start -n com.android.music/com.android.music.MediaPlaybackActivity
撥打到電話:
am start -a android.intent.action.CALL -dtel:10086
瀏覽網頁:
am start -a android.intent.action.VIEW -d http://www.google.cn/
效能測試:
am profile com.android.browser start /sdcard/dump.trace
am profile com.android.browser stop
結合traceview,可以很方便tracejava程式的效能問題。(目前的版本,traceview運行不起來(log 不配對))
5. pm
usage: pm [list|path|install|uninstall]
Android的包管理工具,功能強大
調試時會經常使用:安裝、卸載、禁用等
6. bugreport
bugreport比較簡單,主要是收集系統資訊並輸出到檔案,以供開發人員分析
注意很多資訊可能需要root許可權才能獲得
實際執行的就是dumpstate,擷取的資訊包括:
>>> Logcat
>>> Kernel message
>>> Dumpsys
>>> 其他系統資訊
7. procrank
獲得當前系統中各進程的記憶體使用量快照,只有工程版本才帶此工具。
使用方法:
Usage: procrank [ -W ] [ -v | -r | -p | -u| -h ]
-v Sort by VSS.
-r Sort by RSS.
-p Sort by PSS.
-u Sort by USS.
(Default sort order is PSS.)
-R Reverse sort order (default isdescending).
-w Display statistics for workingset only.
-W Reset working set of allprocesses.
-h Display this help screen.
VSS - Virtual Set Size 虛擬耗用記憶體(包含共用庫佔用的記憶體)
RSS - Resident Set Size 實際使用實體記憶體(包含共用庫佔用的記憶體)
PSS - Proportional Set Size 實際使用的實體記憶體(比例分配共用庫佔用的 記憶體)
USS - Unique Set Size 進程獨自佔用的實體記憶體(不包含共用庫佔用的記憶體)
Procrank在我們機器上統計的並不準確
8. toolbox
Android實現的shell命令少的可憐,功能簡單,不夠強大
工具參看 system/core/toolbox/Android.mk
我們的系統提供了更強大的busybox