Android performance testing tool-Emmagee

Remarks: Personal study notes are organized only for test students to learn. Do not reprint for commercial use. If there are errors or better solutions, you can leave a message and make progress together!

Reference learning (because it has not been updated so much, I no longer pay attention):

https://www.cnblogs.com/zhengna/p/9985576.html
https://cloud.tencent.com/developer/article/1451870
https://blog.csdn.net/zd199218/article/details/80698192
https://www.cnblogs.com/QiangWum/p/12516544.html
https://www.cnblogs.com/shouke/p/10157895.html

  • About Emmagee
  • Features
  • Download and install
  • use
  • testing report
  • Implementation principle
  • scenes to be used

 

 

One: Introduction to Emmagee

Emmagee is an Android performance monitoring tool developed by NetEase , open source

Emmagee is mainly used to monitor the CPU, memory, network traffic, battery current, startup time and status of a single App , and users can customize the monitoring frequency and real-time display of performance, and finally generate a performance statistics file

 

 

 

Two: advantages and disadvantages

advantage:

  • Detect the amount of traffic consumed by the application from the start to the current time
  • Detect the CPU usage and overall CPU usage of the tested application at the current time
  • Detect the amount of memory occupied by the tested application at the current time , the percentage of the total memory occupied , and the amount of remaining memory
  • CSV format report, stored in the phone at the same time
  • In the floating window, you can quickly start or close the mobile phone's wifi network
  • Floating window, showing real-time process status
  • Custom collection interval

 

Disadvantages:

  • Android 5.0 and above: getRunningTasks() and getRunningAppProcesses() are not recommended, and only return your application process, so TopActivity cannot be obtained from Android 5.0.
  • Android 7.0: Google restricts access to /proc, and cannot obtain the pid of the target application from the TOP command in Android 7.0, so it cannot support 7.0 and above.
  • Android version 7.0 and above are not supported
  • Unsupported devices: https://github.com/NetEase/Emmagee/wiki/Some-devices-are-not-supported

 

Problems encountered when I use:

Night God (Android version 5.1 has a compatibility issue): https://blog.csdn.net/weixin_42717928/article/details/106952200

 

 

 

Three: download and install

Official website: https://github.com/NetEase/Emmagee/releases

Click to install to my emulator... Okay, click to open, select the application you want to test

 

 

Four: use

I am very simple, pull the package into the emulator and install it

Opening Emmagee will display the applications currently installed on the system (intervals can be configured in the settings).

After selecting an application, click the "Start Test" button, Emmagee will automatically start the tested application, and display data such as traffic, CPU, memory, etc. at the top. In this state, the tested application can be used arbitrarily, and Emmagee will automatically perform related data After the test is terminated, a corresponding report will be generated and saved in the Android directory.

 

 

Five: Test report

(1) Emmagee-->Settings-->Test Report-->Open. (It's more uncomfortable to see)
(2) Open the CSV file from Emmagee in the Android directory of the phone.

C:\Users\AUSU>adb shell
root@android:/ # cd data/media/0/Emmagee
root@android:/data/media/0/Emmagee # ls
20200625210355_com.ss.android.ugc.aweme.csv
20200625210447_com.ss.android.ugc.aweme.csv
20200625210503_com.ss.android.ugc.aweme.csv
adb pull /data/media/0/Emmagee/20200625232546_com.ss.android.ugc.aweme.csv d:/a

(3) After configuring the email address in the settings, it is automatically sent to the mailbox and opened in the mailbox.

 

I randomly tested Douyin and the report is as follows

Application package name com.ss.android.ugc.aweme                          
Application Name Douyin short video                          
Application PID 2392                          
Machine memory size (MB) 3483.5MB                          
Machine CPU model  ARMv7 Processor rev 0 (v7l)                          
Android system version 4.4.2                          
Phone model SM-N960F                          
UID 10028                          
time Activity name at the top of the stack Application memory PSS (MB) Application memory ratio (%) Machine remaining memory (MB) Application CPU rate (%) Total CPU usage (%) cpu0 total usage rate (%) cpu1 total usage rate (%) Flow (KB) Electricity (%) Current (mA) Temperature (C) Voltage (V) Frame rate
2020/6/25 23:25 ComponentInfo{com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity} 121.74 3.49 2978.24 0 0 0 0 3 90 N/A 42 4.4 51
2020/6/25 23:25 ComponentInfo{com.ss.android.ugc.aweme/com.ss.android.ugc.aweme.splash.SplashActivity} 127.79 3.67 2969.45 12.12 31.5 26.13 36.95 3209 90 N/A 42 4.4 55

You can copy csv data to excel to generate charts

 

数据性能指标:

应用占用内存PSS(MB):应用当前占内存的大小

应用占用内存比(%):应用占总内存的百分比

机器剩余内存(MB):机器当前剩余内存

应用占用CPU率(%):应用占用总CPU的百分比

CPU总使用率(%):CPU的总使用率,所有在运行的应用

CPU0-CPU1总使用率(%):手机是多核的(2核显示cpu0-cpu1,4核显示cpu0-cpu3,10核显示到cpu0-cpu9)

流量(KB):从检测开始到结束所使用的的流量数

电量(%):剩余电池的百分比(有误差,测试尽可能关掉其他应用)

电流(mA):小于0是放电,大于0是充电

温度(C):手机当前的温度

电压(V):一般手机锂电池bai的电压都是标3.7V(实际上手机电池(以下均指普通锂电池)满电电压为4.2,电池用到3.4V以下就没多少电了,再低一点就保护了手机就自己关机了)

帧率:不了解

 

 

 

 

Six: realization principle (to understand)

1:监控CPU
Android系统是基于Linux内核的,所以系统文件的结构和Linux下一样,
系统总体CPU使用信息放在/proc/stat文件下,/proc/cpuinfo文件存放CPU的其它信息,包括CPU名称,直接读取即可。
Emmagee是将选中应用的PID传入,读取/proc/PID/stat文件信息及可获取该PID对应程序的CPU信息。

/proc/stat file information: contains statistical information of many systems and kernels since the start of the system

参数含义(这里以CUP0那行的参数为例子):
name(CPU0):名字

user (1883):从系统启动开始累计到当前时刻,用户态的CPU时间(单位:jiffies) ,不包含nice值为负进程。1jiffies=0.01秒

nice (111):从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间(单位:jiffies)

system (999):从系统启动开始累计到当前时刻,内核态时间(单位:jiffies)

idle (22132):从系统启动开始累计到当前时刻,除硬盘IO等待时间以外其它等待时间(单位:jiffies)

iowait (369):从系统启动开始累计到当前时刻,硬盘IO等待时间(单位:jiffies) 

irrq (0):从系统启动开始累计到当前时刻,硬中断时间(单位:jiffies)

softirq (71):从系统启动开始累计到当前时刻,软中断时间(单位:jiffies)

steal(0):虚拟化环境中运行其他操作系统上花费的时间(自Linux 2.6.11开始)

guest(0):操作系统运行虚拟CPU花费的时间(自Linux 2.6.24开始) 

guest_nice(0):运行一个带nice值的guest花费的时间(自Linux 2.6.33开始)



其他参数:
intr:系统启动以来的所有中断(interrupts)的次数情况

ctxt: 系统启动以来的CPU上下文切换次数

btime:启动时长(单位:秒),从Epoch(即1970零时)开始到系统启动所经过的时长,每次启动会改变
此处指为1593156149,转换北京时间为2020/6/26 15:22:29
(可以去https://unixtime.51240.com/玩玩)

processes:系统启动后所创建过的进程数量。当短时间该值特别大,系统可能出现异常

procs_running:处于运行队列(Runnable)状态的进程个数

procs_blocked:处于等待I/O完成的进程个数

 

/proc/cpuinfo file information:

root@android:/proc # cat cpuinfo

processor       : 0     //系统中逻辑处理核的编号。对于单核处理器,则默认为是其CPU编号,对于多核处理器则可以是物理核、或者使用超线程技术虚拟的逻辑核

vendor_id       : GenuineIntel         //CPU制造商

cpu family      : 6                    //CPU产品系列代号

model           : 60                   //CPU属于其系列中的哪一代的代号

model name      : Intel(R) Core(TM) i5-4200H CPU @ 2.80GHz       //CPU属于的名字及其编号、标称主频

stepping        : 3                    //CPU属于制作更新版本
                               
cpu MHz         : 2796.702             //CPU的实际使用主频

cache size      : 3072 KB              //CPU二级缓存大小

physical id     : 0                    //单个CPU的标号

siblings        : 2                    //单个CPU逻辑物理核数

core id         : 0                    //当前物理核在其所处CPU中的编号,这个编号不一定连续

cpu cores       : 2                    //该逻辑核所处CPU的物理核数

apicid          : 0                    //用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续

initial apicid  : 0                    
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes                 //是否具有浮点运算单元(Floating Point Unit)

fpu_exception   : yes                 //是否支持浮点计算异常

cpuid level     : 13                  //执行cpuid指令前,eax寄存器中的值,根据不同的值cpuid指令会返回不同的内容

wp              : yes                 //表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)

flags           : fpu vme......       //当前CPU支持的功能

bogomips        : 5593.40             //在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second)

clflush size    : 64                  //每次刷新缓存的大小单位

cache_alignment : 64                  //缓存地址对齐单位

address sizes   : 39 bits physical, 48 bits virtual           //可访问地址空间位数

power management:                     //对能源管理的支持

 

 

2:监控内存的实现原理
内存和cpu的处理方式类似。先获取到当被测应用的PID,然后按照PID从 /proc/meminfo文件中获取当前被测应用占用的内存信息。

/proc/meminfo file information

[root@realhost /]# cat /proc/meminfo
MemTotal:         688576 kB     总内存
MemFree:          153736 kB     空闲内存
MemAvailable:     339884 kB     可用内存
Buffers:              16 kB     给文件的缓冲大小
Cached:           267672 kB     高速缓冲存储器
SwapCached:           36 kB     被高速缓冲存储用的交换空间的大小
Active:           222900 kB     活跃使用中的高速缓冲存储器页面文件大小
Inactive:         123700 kB     不经常使用中的告诉缓冲存储器文件大小
Active(anon):      31800 kB     活跃的匿名内存(进程中堆上分配的内存,是用malloc分配的内存)
Inactive(anon):    57272 kB     不活跃的匿名内存
Active(file):     191100 kB     活跃的file内存,//file内存:磁盘高速缓存的内存空间和“文件映射(将物理磁盘上的文件内容与用户进程的逻辑地址直接关联)”的内存空间,其中的内容与物理磁盘上的文件相对应
Inactive(file):    66428 kB   不活跃的file内存     
Unevictable:           0 kB   不能被释放的内存页
Mlocked:               0 kB   mlock()系统调用锁定的内存大小
SwapTotal:       2097148 kB   交换空间总大小
SwapFree:        2096884 kB   空闲交换空间
Dirty:                 0 kB   等待被写回到磁盘的大小
Writeback:             0 kB   正在被写回的大小
AnonPages:         78876 kB     未映射页的大小
Mapped:            28556 kB   设备和文件映射大小
Shmem:             10160 kB   已经被分配的共享内存大小
Slab:             102916 kB   内核数据结构缓存大小
SReclaimable:      49616 kB   可收回slab的大小
SUnreclaim:        53300 kB   不可回收的slab的大小
KernelStack:        4416 kB      kernel消耗的内存
PageTables:         6028 kB      管理内存分页的索引表的大小
NFS_Unstable:          0 kB      不稳定页表的大小
Bounce:                0 kB      在低端内存中分配一个临时buffer作为跳转,把位于高端内存的缓存数据复制到此处消耗的内存
WritebackTmp:          0 kB      USE用于临时写回缓冲区的内存
CommitLimit:     2441436 kB      系统实际可分配内存总量
Committed_AS:     308028 kB      当前已分配的内存总量
VmallocTotal:   34359738367 kB   虚拟内存大小
VmallocUsed:      179588 kB    已经被使用的虚拟内存大小
VmallocChunk:   34359310332 kB   malloc 可分配的最大的逻辑连续的内存大小
HardwareCorrupted:     0 kB      删除掉的内存页的总大小(当系统检测到内存的硬件故障时)
AnonHugePages:      6144 kB      匿名 HugePages 数量
CmaTotal:              0 kB    总的连续可用内存
CmaFree:               0 kB      空闲的连续内存
HugePages_Total:       0      预留HugePages的总个数 
HugePages_Free:        0     池中尚未分配的 HugePages 数量
HugePages_Rsvd:        0        表示池中已经被应用程序分配但尚未使用的 HugePages 数量
HugePages_Surp:        0      这个值得意思是当开始配置了20个大页,现在修改配置为16,那么这个参数就会显示为4,一般不修改配置,这个值都是0
Hugepagesize:       2048 kB     每个大页的大小
DirectMap4k:      108416 kB   映射TLB为4kB的内存数量
DirectMap2M:      940032 kB   映射TLB为2M的内存数量
DirectMap1G:           0 kB     映射TLB为1G的内存数量参考文章:http://linuxperf.com/?P=142

 

 

3:监控流量消耗的实现原理
系统中有存放整体流量和针对当程序的流量统计,
/proc/net/dev和/proc/uid_stat/UID下存放tcp_rcv和tcp_send文件,分别存放下行流量和上行流量,操作前后相减就得出结果 。

 

4:监控电量的实现原理
电量、电压和温度情况是通过监听系统的电池管理事件的广播来获取的。

 

5:监控启动时间的实现原理
我们点击界面的开始测试时,程序会启动EmmageeService,之后所有的数据统计以及更新都是EmmageeService 进行处理的。 
EmmageeService会在onStartCommand()里面启动一个线程“handler.postDelayed(task, 1000)”,
进行数据的更新同时会尝试通过ActivityManger从logcat中获取到软件的启动时间。

 

 

 

 

Seven: usage scenarios

Example 1: Related performance status of the app for the first start

Scenario description: Click on the app to start the app until the main page of the app appears.

测试操作:
1.打开Emmagee
2.选择app,点击“开始测试”,出现主页面后,点击“停止测试”
3.用手机清理软件,清理“被测app”。
4.重复步骤2

data analysis:

In practice, it is found that the startup time is often unavailable

Solution: Set the time of the acquisition frequency to the minimum value, such as 1s, so that Emmagee can roughly calculate the time consumption of this function according to the "time" column in the test report.

The "average" and "peak" of various types of data can be calculated based on multiple test data

 

Example 2: Related performance status of the app's secondary startup

Scenario description: click on the app, start the app until the main page of the app appears, exit the app

测试操作:

1.打开Emmagee
2.选择app,点击“开始测试”,出现主页面后,退出app,点击“停止测试”
3.重复步骤2

 

Example 3: Test a certain process, the purpose is to find the performance "bottleneck"

For a certain business flow, do a complete business process operation

According to the .csv file generated by the test, draw a graph of the relevant data and check the curve change-stable? Ups and downs? Or is it "turning around"? If it is not very stable, it means that there may be a bottleneck in performance, and further analysis is needed for the operation step.

 

Guess you like

Origin blog.csdn.net/weixin_42717928/article/details/106950481