51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2711|回复: 4

[原创] Android性能测试指标的获取——cpu

[复制链接]

该用户从未签到

发表于 2016-9-27 20:23:14 | 显示全部楼层 |阅读模式
0. 手机硬件信息
1. CPU 相关
1.1 dumpsys cpuinfo
1.2 cat /proc/pid/stat
1.3 cat /proc/stat
1.4 cat /proc/cpuinfo
1.5 根据cpu时间片计算应用cpu使用率
1.6 通过top命令获取应用cpu使用率(kat使用方式)
1.7  获取cpu核数
2. 内存相关
2.1 最大内存限制
2.2 获得内存相关信息 cat /proc/meminfo
2.3  MemoryInfo
2.4 通过dumpsys meminfo + pkgname(kat采用方式)
3. 流量
3.1 单个app流量(uid)
4. 帧率
4.1 帧率获取方式
4.2 获取TopActivity
5. 温度
5.1 cpu温度获取方式
5.2 电池温度获取

------------------------------------------------------------------------------------------------
硬件环境为:三星  SM-A3000
0. 手机硬件信息
手机硬件是影响性能数据的关键影响因素。
性能评估应该在设备硬件信息的基础上进行。

1. CPU 相关
1.1  dumpsys cpuinfo
shell@a3ltechn:/ $ dumpsys cpuinfo
Load: 5.6 / 4.76 / 4.6
CPU usage from 16693ms to 9622ms ago:
  19% 314/adbd: 2.5% user + 16% kernel / faults: 54 minor
  6.6% 14372/kworker/2:0: 0% user + 6.6% kernel
  4.2% 13893/com.tencent.wstt.gt: 4.1% user + 0.1% kernel / faults: 76 minor
  4.2% 14111/kworker/1:0: 0% user + 4.2% kernel
  2.5% 834/system_server: 1.5% user + 0.9% kernel / faults: 35 minor 2 major
  1.4% 13670/kworker/0:1: 0% user + 1.4% kernel
  1.2% 235/surfaceflinger: 0.1% user + 1.1% kernel
  0.9% 1128/com.android.systemui: 0.8% user + 0.1% kernel / faults: 18 minor
  0.8% 537/com.kingroot.kinguser:service: 0.7% user + 0.1% kernel / faults: 209minor
  0.8% 5237/com.tencent.android.qqdownloader:connect: 0.2% user + 0.5% kernel /faults: 187 minor 70 major
  0.1% 1//init: 0% user + 0.1% kernel / faults: 66 minor
  0.2% 425/kuInotify: 0% user + 0.2% kernel
  0.1% 620/sh: 0% user + 0.1% kernel / faults: 308 minor
  0.2% 2435/mpdecision: 0% user + 0.2% kernel
  0.2% 3876/com.tencent.qqmusicQPlayerService: 0.1% user + 0.1% kernel / faults: 2 minor
  0.2% 5253/com.tencent.android.qqdownloader: 0.2% user + 0% kernel / faults: 2minor
  0.2% 7153/android.process.media: 0.1% user + 0.1% kernel / faults: 20 minor
  0.2% 11580/kworker/u8:2: 0% user + 0.2% kernel
  0% 3/ksoftirqd/0: 0% user + 0% kernel
  0% 12/ksoftirqd/1: 0% user + 0% kernel
  0.1% 33/kworker/u9:0: 0% user + 0.1% kernel
  0.1% 155/mmcqd/0: 0% user + 0.1% kernel
  0.1% 492/mdss_fb0: 0% user + 0.1% kernel
  0.1% 1497/com.sec.android.provider.logsprovider: 0.1% user + 0% kernel / faults: 21 minor 14 major
  0% 2385/com.tencent.map:xg_service_v2: 0% user + 0% kernel / faults: 7 minor
  0% 3475/com.tencent.qqmusic: 0% user + 0% kernel / faults: 33 minor
  0% 4481/com.tencent.map: 0% user + 0% kernel / faults: 3 minor
  0.1% 14265/kworker/u8:3: 0% user + 0.1% kernel
  0.1% 24649/kworker/0:1H: 0% user + 0.1% kernel
+0% 14501/logcat: 0% user + 0% kernel
+0% 14531/sh: 0% user + 0% kernel
24% TOTAL: 10% user + 14% kernel + 0% iowait + 0% softirq


1.2  cat /proc/pid/stat
shell@a3ltechn:/ $ cat /proc/13893/stat
13893      (tencent.wstt.gt)            S                236             236           0               0            -1           1077936448               32761             1869 562           0           
6171(13)           798(14)              14                20             0             35              0                53677782 625696768 12152 4294967295 1 1 0 0 0 0 4612 0 38136 4294967 295 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0

大家都是用13  14 作为本app使用的时间片

1.3 cat /proc/stat
第一行数据表示cpu的总得使用情况
接着cpu0、cpu1、cpu2、cpu3 表示cpu为四核
第一行的数值表示的是CPU总的使用情况,所以我们只要用第一行的数字计算就可以了。下表解析第一行各数值的含义:
参数          解析(单位:jiffies)
(jiffies是内核中的一个全局变量,用来记录自系统启动一来产生的节拍数,在linux中,一个节拍大致可理解为操作系统进程调度的最小时间片,不同linux内核可能值有不同,通常在1ms到10ms之间)
user ( 15579 )    从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负进程。
nice (99)      从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间
system (13680)  从系统启动开始累计到当前时刻,处于核心态的运行时间
idle (698457)   从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间
iowait (10939) 从系统启动开始累计到当前时刻,IO等待时间(since 2.5.41)
irq (40)           从系统启动开始累计到当前时刻,硬中断时间(since 2.6.0-test4)
softirq (651)      从系统启动开始累计到当前时刻,软中断时间(since 2.6.0-test4)
stealstolen(0)     which is the time spent in other operating systems when running in a virtualized environment(since 2.6.11)
guest(0)        which is the time spent running a virtual  CPU  for  guest operating systems under the control of the Linux kernel(since 2.6.24)
结论:总的cpu时间totalCpuTime = user + nice + system + idle + iowait + irq + softirq + stealstolen +guest
通过   idle 是cpu空闲时间可以计算出整个cpu的使用率。

(totalCpuTime2 -idle2)-(totalCpuTime1 -idle1)    /   (totalCpuTime2 - totalCpuTime1)


2|shell@a3ltechn:/proc $ cat stat
cpu  1865179 110769 2171734 28665447 122413 371 59060 0 0 0
cpu0 1234985 64059 1622254 28326111 111975 321 48131 0 0 0
cpu1 356972 27039 303011 33268 42 27 6651 0 0 0
cpu2 228497 15037 211115 33486 93 17 3090 0 0 0
cpu3 44725 4634 35354 272582 10303 6 1188 0 0 0
intr 127334512 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 51107631 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5886484 0 0 0 0 0 0 0 35 0 0 0 0 0 0 0 0 0 636925 6 5 0 10 0 0 0 1371974 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 5262657 0 435617 0 0 0 0 0 0 0 0 22020533 0 0 0 17379 0 0 0 203011 5 0 1454005 943548 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5326760 0 0 1815556 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 70 4 0 2 22333 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 178941 17 0 0 0 0 0 0 0 0 379 0 0 0 0 0 0 0 0 0 0 0 0 0 0 773 492 0 59 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 117 5 0
ctxt 342316223
btime 1455761173
processes 1145328
procs_running 2
procs_blocked 0
softirq 49561716 93738 13218862 144172 305576 93738 93738 3878678 7708098 13938 24011178

1.4 cat /proc/cpuinfo
shell@a3ltechn:/proc $ cat cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 0 (v7l)
BogoMIPS        : 38.40
Features        : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 0

processor       : 1
model name      : ARMv7 Processor rev 0 (v7l)
BogoMIPS        : 38.40
Features        : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 0

processor       : 2
model name      : ARMv7 Processor rev 0 (v7l)
BogoMIPS        : 38.40
Features        : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 0

processor       : 3
model name      : ARMv7 Processor rev 0 (v7l)
BogoMIPS        : 38.40
Features        : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd03
CPU revision    : 0

Hardware        : Qualcomm Technologies, Inc MSM8916
Revision        : 0006
Serial          : 000007610000e054
Processor       : ARMv7 Processor rev 0 (v7l)
1.5 根据cpu时间片计算应用cpu使用率
cpu时间片总和:  allCpu
/proc/stat  读取所有时间片,累加

process对应时间片:processCpu
读取/proc/pid/stat 的时间片   读取13 、 14 列  累加

(processCpu2 - processCpu1)   /   (allCpu2-allCpu 1)

1.6 通过top命令获取应用cpu使用率(kat使用方式)


1.7  获取cpu核数
https://github.com/facebook/devi ... ass/DeviceInfo.java
/**
* Reads the number of CPU cores from {@code /sys/devices/system/cpu/}.
*
* @return Number of CPU cores in the phone, or DEVICEINFO_UKNOWN = -1 in the event of an error.
*/
public static int getNumberOfCPUCores() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// Gingerbread doesn't support giving a single application access to both cores, but a
        // handful of devices (Atrix 4G and Droid X2 for example) were released with a dual-core
        // chipset and Gingerbread; that can let an app in the background run without impacting
        // the foreground application. But for our purposes, it makes them single core.
return 1;
    }
int cores;
try {
        cores = new File("/sys/devices/system/cpu/").listFiles(CPU_FILTER).length;
    } catch (SecurityException e) {
        cores = DEVICEINFO_UNKNOWN;
    } catch (NullPointerException e) {
        cores = DEVICEINFO_UNKNOWN;
    }
return cores;
}

private static final FileFilter CPU_FILTER = new FileFilter() {
@Override
public boolean accept(File pathname) {
        String path = pathname.getName();
//regex is slow, so checking char by char.
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (!Character.isDigit(path.charAt(i))) {
return false;
                }
            }
return true;
        }
return false;
    }
};

回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2016-9-27 20:24:01 | 显示全部楼层
有字数限制 写好的文章发不全啊
回复 支持 反对

使用道具 举报

  • TA的每日心情
    无聊
    前天 09:12
  • 签到天数: 918 天

    连续签到: 3 天

    [LV.10]测试总司令

    发表于 2016-9-28 09:33:24 | 显示全部楼层
    harryhappy 发表于 2016-9-27 20:24
    有字数限制 写好的文章发不全啊

    是的 有数字限制的,建议你可以另外开个贴,然胡标题说明下哦!
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 07:17
  • 签到天数: 2636 天

    连续签到: 4 天

    [LV.Master]测试大本营

    发表于 2016-9-30 10:31:35 | 显示全部楼层
    支持,建议搞个附件
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-3-29 05:48 , Processed in 0.065222 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表