使用screenrecord对APP性能测试中的响应时间指标进行收集

6 篇文章 0 订阅

APP性能测试中响应时间是一个重要的指标。

之前的测试中主要使用的是录屏的方式记录响应时间——在A手机上操作,同时使用B手机进行录制,然后对录制到的视频进行帧分析计算响应时间。很显然,这个方法很麻烦~~

研究了一下,我们可以通过Log查看Activity的Launchtime来对响应时间进行收集。

但是这个方法有很多局限:

首先这个方法只能测试对涉及Activity启动项的测试,但是在我们需要测试的场景中有些场景是不涉及activity的;

其次Log中的统计的时间是系统从开始处理启动activity的时间到完成运行layout和draw函数的时间,而不包括点击icon到系统接收到消息的时间。显然,这个时间也不包括启动中异步UI绘制的时间。所以这个时间不能很好的反映用户实际体验到的时间。


今天无意中发现在Android 4.4之后多了一条命令——"screenrecord",使用这条命令我们可以对屏幕的操作进行录制。因此我们可以继续使用第一种方法来获取响应时间,并且不需要使用另外一台手机进行录制。

使用方法如下:

把待测手机连上电脑,输入如下命令:

adb shell screenrecord /sdcard/demo.mp4
然后屏幕的操作即会被录制在手机的/sdcard/demo.mp4文件中,然后我们通过下面的命令将该文件pull到电脑上进行帧分析即可:

adb pull /sdcard/demo.mp4 C:\Users\XXXX\Desktop\record


关于screenrecord还有很多参数可以设置:

我们可以通过 --help进行查看:

$ adb shell screenrecord --help
Usage: screenrecord [options] <filename>
 
Records the device's display to a .mp4 file.
 
Options:
--size WIDTHxHEIGHT
    Set the video size, e.g. "1280x720".  Default is the device's main
    display resolution (if supported), 1280x720 if not.  For best results,
    use a size supported by the AVC encoder.
--bit-rate RATE
    Set the video bit rate, in megabits per second.  Default 4Mbps.
--time-limit TIME
    Set the maximum recording time, in seconds.  Default / maximum is 180.
--rotate
    Rotate the output 90 degrees.
--verbose
    Display interesting information on stdout.
--help
    Show this message.
 
Recording continues until Ctrl-C is hit or the time limit is reached.
用法依次分别如下:

设置录制分辨率,不设置的话就是手机的默认分辨率:

adb shell screenrecord --size 1280*720 /sdcard/demo.mp4
设置比特率,不设置的话为默认4Mbps:
adb shell screenrecord --bit-rate 6000000 /sdcard/demo.mp4
设置录制时间,默认最大时间为180s:

adb shell screenrecord  --time-limit 10 /sdcard/demo.mp4
旋转90度:

adb shell screenrecord  --rotate /sdcard/demo.mp4
在命令行中显示log:

$ adb shell screenrecord --time-limit 10 --verbose /sdcard/demo.mp4
Main display is 1080x1920 @60.00fps (orientation=0)
Configuring recorder for 1080x1920 video at 4.00Mbps
Content area is 1080x1920 at offset x=0 y=0
Time limit reached
Encoder stopping; recorded 96 frames in 10 seconds
Stopping encoder and muxer
Executing: /system/bin/am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/demo.mp4

Broadcasting: Intent { act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=file:///sdcard/demo.mp4 }
Broadcast completed: result=0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值