monkey命令——壓力測試——個人總結


約束限制及確定對應包名

 

1、約束限制

-p   <allowed-package-name>              ——1個 -p 選項只能用於一個包。指定多個包,需要使用多個 -p 選項

 

注意:

            找到對應的包名后,就可以通過monkey命令來進行測試了。例如:adb shell monkey -v -p your.www.com 500  。

            表示測試觸發500個事件(500個事件要按比例分攤到9個事件當中)。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

2、插入動作(事件)之間的時間延遲

--throttle   5000           ——這里的5000為毫秒單位。通過這個選項,可以降低monkey的執行速度;如果不指定該選項,Monkey將不會被延遲,事件將盡可能快的被產生。

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

3、偽隨機數

-s  <seed>                 ——偽隨機數生成器的seed值。如果用相同的seed值再次運行monkey,它將生成相同的事件序列,對9個事件分配相同的百分比

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

4、日志級別

-v                               ——命令行的每一個-v將增加反饋信息的級別。

 

-v

-v    -v  

-v    -v     -v

 

注意:最多3個;

 

 

 

 

========================================================================================================

 

 

 

 

 調試選項

 

--dbg-no-events:初始化啟動的activity,但是不產生任何事件。


--hprof:指定該項后在事件序列發送前后會立即生成分析報告  —— 一般建議指定該項。


--ignore-crashes:忽略崩潰


--ignore-timeouts:忽略超時


--ignore-security-exceptions:忽略安全異常


--kill-process-after-error:發生錯誤后直接殺掉進程


--monitor-native-crashes:跟蹤本地方法的崩潰問題


--wait-dbg:知道連接了調試器才執行monkey測試。

 

 

 

 

====================================================================================================================

九個事件及百分比控制

1、九個事件

 

--pct-touch <percent> 0
調整觸摸事件的百分比(觸摸事件是一個down-up事件,它發生在屏幕上的某單一位置)(——點擊事件,涉及down、up)

 

 

--pct-motion <percent> 1
調整動作事件的百分比(動作事件由屏幕上某處的一個down事件、一系列的偽隨機事件和一個up事件組成) (——注:move事件,涉及down、up、move三個事件)

 

 

 

--pct-trackball <percent> 2
調整軌跡事件的百分比(軌跡事件由一個或幾個隨機的移動組成,有時還伴隨有點擊)--(軌跡球)

 

 

 

--pct-nav <percent> 3
調整“基本”導航事件的百分比(導航事件由來自方向輸入設備的up/down/left/right組成)

 

 

 

--pct-majornav <percent> 4
調整“主要”導航事件的百分比(這些導航事件通常引發圖形界面中的動作,如:5-way鍵盤的中間按鍵、回退按鍵、菜單按鍵)

 

 

 

--pct-syskeys <percent> 5
調整“系統”按鍵事件的百分比(這些按鍵通常被保留,由系統使用,如Home、Back、Start Call、End Call及音量控制鍵)

 

 

 

--pct-appswitch <percent> 6
調整啟動Activity的百分比。在隨機間隔里,Monkey將執行一個startActivity()調用,作為最大程度覆蓋包中全部Activity的一種方法。(從一個Activity跳轉到另一個Activity)

 

 

 

--pct-flip <percent> 7
調整“鍵盤翻轉”事件的百分比。

 

 

 

--pct-anyevent <percent> 8
調整其它類型事件的百分比。它包羅了所有其它類型的事件,如:按鍵、其它不常用的設備按鈕、等等。

 

 

 

紅色的數字對應下面百分比對應的數字。比如下圖中0:15.0%,表示分配--pct-touch事件15%。測試100次分配15次測試down-up。

 

 

2、百分比控制

如果在monkey參數中不指定上述參數,這些動作都是隨機分配的,9個動作其每個動作分配的百分比之和為100%,我們可以通過添加命令選項來控制每個事件的百分比,進而可以將操作限制在一定的范圍內。

我們先來看一下不加動作百分比控制,系統默認分配事件百分比的情況

命令:adb shell monkey -v -p your.www.com 500

結果:

 

 

 

 

 

再看一下指定事件,控制事件百分比之后的情況

命令:adb shell monkey -v -p your.www.com --pct-anyevent 100 500

結果:

 

 

 

 

說明:--pct-anyevent 100 表明pct-anyevent所代表的事件的百分比為100%。

 

 

 

=======================================================================================================

 

 

monkey 報告組成

 

 

1.第一部分:包含 seed值,執行次數、包名

 

 

 

第二部分:被測設備上的所有應用包名,本次測試使用到哪些包,未使用哪些包(建議測試某app時,殺掉其他應用進程)

 

 

 

 

第三部分:各個事件所占百分比,只顯示了事件的代號,沒有顯示具體什么時間,可以查詢monkey源代碼中各代號對應的事件,所有事件包含:

 -

 

-pct-touch {+百分比}

調整觸摸事件的百分比(觸摸事件是一個down-up事件,它發生在屏幕上的某單一位置)

adb shell monkey -p com.htc.Weather--pct-touch 10 1000

 

 

 

--pct-motion {+百分比}

調整動作事件的百分比(動作事件由屏幕上某處的一個down事件、一系列的偽隨機事件和一個up事件組成)adb shell monkey -p com.htc.Weather --pct-motion 20 1000

 

 

 

 --pct-trackball {+百分比}

調整軌跡事件的百分比(軌跡事件由一個或幾個隨機的移動組成,有時還伴隨有點擊)

adb shell monkey -p com.htc.Weather--pct-trackball 30 1000

 

 

 

--pct-nav {+百分比}

 調整“基本”導航事件的百分比(導航事件由來自方向輸入設備的up/down/left/right組成)

 

 

 

--pct-majornav {+百分比}

調整“主要”導航事件的百分比(這些導航事件通常引發圖形界面中的動作,如:5-way鍵盤的中間按鍵、回退按鍵、菜單按鍵)

adb shell monkey -p com.htc.Weather--pct-majornav 50 1000

 

 

 

--pct-syskeys {+百分比}

調整“系統”按鍵事件的百分比(這些按鍵通常被保留,由系統使用,如Home、Back、Start Call、End Call及音量控制鍵)

adb shell monkey -p com.htc.Weather--pct-syskeys 60 1000

 

 

 

--pct-appswitch {+百分比}

調整啟動Activity的百分比。在隨機間隔里,Monkey將執行一個startActivity()調用,作為最大程度覆蓋包中全部Activity的一種方法

adb shell monkey -p com.htc.Weather--pct-appswitch 70 1000

 

 

 

--pct-anyevent {+百分比}

調整其它類型事件的百分比。它包羅了所有其它類型的事件,如:按鍵、其它不常用的設備按鈕、等等

 

 

 

 

--pct -anyevent  {+百分比}

指定多個事件的百分比

adb shell monkey -p com.htc.Weather--pct-anyevent 50 --pct-appswitch 50 1000

 

注意:各事件類型的百分比總數不能超過100%; Bottom of Form

 

 

 

 

 

 

第四部分:具體事件

 

 

 

第五部分:log 完成

如果Monkey測試順利執行完成,在log的最后,會打印出當前執行事件的次數和所花費的時間;// Monkey finished代表執行完成。
如果Monkey執行中斷,在log的最后也能查看到當前已執行的次數。Monkey執行完成的log具體如下: Events injected: 6000 :Dropped: keys=0 pointers=9 trackballs=0 flips=0 ## Network stats: elapsed time=808384ms (0ms mobile, 808384ms wifi, 0msnot connected) // Monkey finished

 

 

 

五、分析報告:

1.在日志中搜索關鍵字:

1)搜索報告中的關鍵字“ANR”,看有無應用無響應的事件(Application Not Responding)

2)搜索報告中的關鍵字“crash”,看有無崩潰的事件

3)搜索報告中的關鍵字“exception”,看有無其他異常事件。(如果出現空指針, NullPointerException,需格外重視)

 

 

下面的屬於monkey自己的問題。不用管。

:Sending Flip keyboardOpen=false

Got IOException performing flipjava.io.IOException: write failed: EINVAL (Invalid argument)

// Injection Failed

4)內存泄露問題搜索"GC"(需進一步分析)

 

 

 

 

 

 

 

 

2. 初步分析法: monkey出現錯誤后,一般的分析步驟

1)先找到出現錯誤的位置

2)查看出現錯誤之前2個switch之間的activity

3)手動執行事件,復現問題

4)若以上步驟還不能找出,產生錯誤時,有會seed值,輸入相同的seed值,重新按照之前命令跑monkey

 

 

 

 

 

 

3.詳細分析法:

1) ANR問題:在日志中搜索“ANR”(“Application Not Responding"),說明有bug,出現ANR,一般是主線程的響應超過5秒,或者BroadcastReceiver沒有在10秒內作出響應。

       這個就是一個比較嚴重的缺陷。把耗時的操作另起線程來處理就可以了。

 

 

2)分析log中的具體信息:

查看log中第一個Switch,主要是查看Monkey執行的是那一個Activity,譬如下面的log中,執行的是com.tencent.smtt.SplashActivity,在下一個swtich之間的,如果出現了崩潰或其他異常,可以在該Activity中查找問題的所在。

:Switch:#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10000000;component=com.tencent.smtt/.SplashActivity;end

  // Allowing start of Intent {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]cmp=com.tencent.smtt/.SplashActivity } in package com.tencent.smtt

 

 

 

3)內存泄漏

 

1. 內存泄漏彈出out of memory對話框

 

2. 對於有內存泄漏但是沒有單出out of memory對話框的情況,可以通過logcat文件GC出信息,(GC:java的垃圾回收機制)


GC_FOR_ALLOC: 因為在分配內存時候內存不夠引起的


GC_EXPLICIT 表明GC被顯式請求觸發的,如System.gc調用,


GC_CONCCURRENT: 表明GC在內存使用率達到一定的警戒值時候,自動觸發


GC_BEFORE_OOM 表明在虛擬機拋出內存不夠異常oom之前,執行最后一次回收內存垃圾

 

 

 

 

2.發現內存泄露--內存報告分析(利用hprof參數的內存快照生成內存報告)

 

在發現內存泄露后,可以執行相同的monkey,只需多加一個參數--hprof 

 

adb shell monkey -p 包名  --hprof --throttle 100  --pct-touch 50 --pct-motion 50 -v -v -v 1000 >c:\monkey.txt

 

 

如果指定了這個選項,monkey會在發送時間的前后生成app內存快照文件,一般會在手機設備的/data/misc目錄下生成hprof的文件。

 

(注:  /data/misc  需要root權限,可以在手機上安裝個RE查看或通過手機助手查看)

 

ps:文件轉換:配置monkey測試時的sdk-tools下查看是否hprof-conv命令,在命令行輸入hprof-conv -help得知文件轉化用法,直接轉化就行,由.hprof轉化成.conv格式。

                          轉化后的文件用eclipse的Memory Analyzer tool(MAT)查看(此插件可以下載),可以點擊 Reports->Leak Suspects鏈接來生成報告。

 

 

==================================================================================================

 

adb shell monkey

  -p com.android.recorder

  --throttle 360

  --ignore-crashes

  --monitor-native-crashes

  --ignore-security-exceptions

  --ignore-timeouts

  --ignore-native-crashes

  --pct-syskeys 10

  --pct-nav 20

  --pct-majornav 20

  --pct-touch 40

  --pct-appswitch 10

  -v -v -v 20000

 

*#*#3646633#*#* mtklogger

 

復制代碼
ci@clinux:~/mp_mtk$  adb shell monkey --help
** Error: Unknown option: --help
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
              [--ignore-crashes] [--ignore-timeouts]
              [--ignore-security-exceptions]
              [--monitor-native-crashes] [--ignore-native-crashes]
              [--kill-process-after-error] [--hprof]
              [--pct-touch PERCENT] [--pct-motion PERCENT]
              [--pct-trackball PERCENT] [--pct-syskeys PERCENT]
              [--pct-nav PERCENT] [--pct-majornav PERCENT]
              [--pct-appswitch PERCENT] [--pct-flip PERCENT]
              [--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]
              [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
              [--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
              [--wait-dbg] [--dbg-no-events]
              [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
              [--port port]
              [-s SEED] [-v [-v] ...]
              [--throttle MILLISEC] [--randomize-throttle]
              [--profile-wait MILLISEC]
              [--device-sleep-time MILLISEC]
              [--randomize-script]
              [--script-log]
              [--bugreport]
              [--periodic-bugreport]
              COUNT

ci@clinux:~/mp_mtk$ 
復制代碼

 

復制代碼
adb shell monkey
     -p com.letv.android.recorder 
    --throttle 360 
    --ignore-crashes 
    --monitor-native-crashes 
    --ignore-security-exceptions 
    --ignore-timeouts 
    --ignore-native-crashes 

    --pct-syskeys 10 
    --pct-nav 20 
    --pct-majornav 20 
    --pct-touch 40 
    --pct-appswitch 10 
    -v -v -v 20000

adb shell monkey -p com.letv.android.recorder --throttle 360 --ignore-crashes --monitor-native-crashes --ignore-security-exceptions --ignore-timeouts --ignore-native-crashes --pct-syskeys 10 --pct-nav 20 --pct-majornav 20 --pct-touch 40 --pct-appswitch 10 -v -v -v 20000
Category Option Description
General --help Prints a simple usage guide.
-v

Each -v on the command line will increment the verbosity level. Level 0 (the default) provides little information beyond startup notification, test completion, and final results. Level 1 provides more details about the test as it runs, such as individual events being sent to your activities. Level 2 provides more detailed setup information such as activities selected or not selected for testing.

命令行的每一個-v將增加反饋信息的級別。Level 0(缺省值)除啟動提示、測試完成和最終結果之外,提供較少信息。Level 1提供較為詳細的測試信息,如逐個發送到Activity的事件。Level 2提供更加詳細的設置信息,如測試中被選中的或未被選中的Activity。

 

Events -s <seed>

Seed value for pseudo-random number generator. If you re-run the Monkey with the same seed value, it will generate the same sequence of events.

產生隨機事件的種子,相同的值產生相同的事件序列

--throttle <milliseconds>

Inserts a fixed delay between events. You can use this option to slow down the Monkey. If not specified, there is no delay and the events are generated as rapidly as possible.

設置兩次事件之間的事件間隔.通過這個參數降低速度,如果不指定該參數,系統會盡可能快的發送事件

--pct-touch <percent>

Adjust percentage of touch events. (Touch events are a down-up event in a single place on the screen.)

調整設置觸摸事件的百分比

--pct-motion <percent>

Adjust percentage of motion events. (Motion events consist of a down event somewhere on the screen, a series of pseudo-random movements, and an up event.)

調整設置滑動事件的百分比

--pct-trackball <percent>

Adjust percentage of trackball events. (Trackball events consist of one or more random movements, sometimes followed by a click.)

調整設置軌跡球事件的百分比

--pct-nav <percent>

Adjust percentage of "basic" navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)

調整設置導航事件 up/down/left/right)百分比

--pct-majornav <percent>

Adjust percentage of "major" navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.)

調整設置(主要導航事件 back key 、 menu key)百分比

--pct-syskeys <percent>

Adjust percentage of "system" key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.)

調整設置系統按鍵事件 Home 、Back 、startCall 、 endCall 、 volumeControl)百分比

--pct-appswitch <percent>

Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package.

調整設置(activity之間的切換)百分比

--pct-anyevent <percent>

Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.

調整設置 (  任意事件)百分比

Constraints -p <allowed-package-name>

If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you'll need to specify those packages as well. If you don't specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times — one -p option per package.

指定有效的package(如不指定,則對系統中所有package有效),一個-p 對應一個有效package, 如:-p com.ckt -p com.ckt.asura;可以指定多個

-c <main-category>

If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don't specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times — one -c option per category.

activity必須至少包含一個指定的category,才能被啟動,否則啟動不了;

Debugging --dbg-no-events

When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application.

設置此選項,Monkey將執行初始啟動,進入到一個測試Activity,然后不會再進一步生成事件。為了得到最佳結果,把它與-v、一個或幾個包約 束、以及一個保持Monkey運行30秒或更長時間的非零值聯合起來,從而提供一個環境,可以監視應用程序所調用的包之間的轉換。

 

--hprof

If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files.

設置此選項,將在Monkey事件序列之前和之后立即生成profiling報告。這將會在data/misc中生成大文件(~5Mb),所以要小心使用它。

--ignore-crashes

Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

通常,當應用程序崩潰或發生任何失控異常時,Monkey將停止運行。如果設置此選項,Monkey將繼續向系統發送事件,直到計數完成。

--ignore-timeouts

Normally, the Monkey will stop when the application experiences any type of timeout error such as a "Application Not Responding" dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

通常,當應用程序發生任何超時錯誤(如“Application Not Responding”對話框)時,Monkey將停止運行。如果設置此選項,Monkey將繼續向系統發送事件,直到計數完成。

--ignore-security-exceptions

Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

通常,當應用程序發生許可錯誤(如啟動一個需要某些許可的Activity)時,Monkey將停止運行。如果設置了此選項,Monkey將繼續向系統發送事件,直到計數完成。

--kill-process-after-error

Normally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event.

通常,當Monkey由於一個錯誤而停止時,出錯的應用程序將繼續處於運行狀態。當設置了此選項時,將會通知系統停止發生錯誤的進程。注意,正常的(成功的)結束,並沒有停止啟動的進程,設備只是在結束事件之后,簡單地保持在最后的狀態。

--monitor-native-crashes

Watches for and reports crashes occurring in the Android system native code. If --kill-process-after-error is set, the system will stop.

監視並報告Android系統中本地代碼的崩潰事件。如果設置了--kill-process-after-error,系統將停止運行。

--wait-dbg

Stops the Monkey from executing until a debugger is attached to it.

停止執行中的Monkey,直到有調試器和它相連接

 

 

 

===========================================================================================================

 

 

adb shell monkey -p com.android.calculator2      --kill-process-after-error     --ignore-timeouts     --ignore-security-exceptions    -s 200     -v -v -v      --throttle 500             

500>C:\Users\del\Desktop\a.txt

 

=====================================================================================================

 

adb shell monkey -p com.android.calculator2 -s 200 --throttle 50 -v -v -v  1000 > C:\Users\del\Desktop\a.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM