zoukankan      html  css  js  c++  java
  • 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
    CategoryOptionDescription
    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:UsersdelDesktopa.txt

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

    adb shell monkey -p com.android.calculator2 -s 200 --throttle 50 -v -v -v  1000 > C:UsersdelDesktopa.txt

  • 相关阅读:
    C++Josephus问题
    C++背包示例
    C++1000以内的质数
    as3+asp+access编码
    fb设置flashplayer
    三视图示例
    正确实现 IDisposable 接口
    .net垃圾回收和CLR 4.0对垃圾回收所做的改进之二
    .net垃圾回收和CLR 4.0对垃圾回收所做的改进之三
    CLR 全面透彻解析:大型对象堆揭秘
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/13170206.html
Copyright © 2011-2022 走看看