性能测试工具自己写的:

# encoding:utf-8
import os
import pandas
import time

package_name = "com.kakarote.crm9" #手机app的包名


class performanceTooll():
    # 内存
    def get_mem(self):
        get_meminfo = os.popen("adb shell dumpsys meminfo %s" % package_name).readlines()
        # print(get_meminfo)
        for meminfo_every_line in get_meminfo:
            if meminfo_every_line.count(" TOTAL:") > 0:
                # print(meminfo_every_line)
                meminfo_total = meminfo_every_line.split(":")[1].split("TOTAL")[0].lstrip().rstrip()
                print(meminfo_total)
        #         return meminfo_total
        list = []
        list.append(meminfo_total)
        mem = pandas.DataFrame({"meminfo": list})
        mem.to_csv("mem.csv", index=False, sep=',', mode="a", header=False)

    # cpu
    def get_cpuinfo(self):
        get_cpuinfo = os.popen("adb shell dumpsys cpuinfo %s" % package_name).readlines()
        # print(get_meminfo)
        for cpuinfo_every_line in get_cpuinfo:
            if cpuinfo_every_line.count(" TOTAL:") > 0:
                # print(meminfo_every_line)
                cpuinfo_total = cpuinfo_every_line.split("TOTAL:")[0].lstrip().rstrip()
                print(cpuinfo_total)
        #         return meminfo_total
        list = []
        list.append(cpuinfo_total)
        mem = pandas.DataFrame({"cpuinfo": list})
        mem.to_csv("cpu.csv", index=False, sep=',', mode="a", header=False)

    #      battery电量
    def get_batteryinfo(self):
        get_batteryinfo = os.popen("adb shell dumpsys battery").readlines()
        # print(get_meminfo)
        for batteryinfo_every_line in get_batteryinfo:
            # print(batteryinfo_every_line)
            if batteryinfo_every_line.count("level:") > 0:
                # print(meminfo_every_line)
                batteryinfo_total = batteryinfo_every_line.split(":")[1].lstrip().rstrip()
                print(batteryinfo_total)
        #         return meminfo_total
        list = []
        list.append(batteryinfo_total)
        mem = pandas.DataFrame({"batteryinfo": list})
        mem.to_csv("battery.csv", index=False, sep=',', mode="a", header=False)
#     响应时间
    def get_time(self):
        get_timeinfo=os.popen("adb shell am start -W com.kakarote.crm9/com.kakarote.crm9.MainActivity").readlines()
        for timeinfo_every_line in get_timeinfo:
            # print(batteryinfo_every_line)
            if timeinfo_every_line.count("ThisTime:") > 0:
                # print(meminfo_every_line)
                timeinfo_tistime = timeinfo_every_line.split(":")[1].lstrip().rstrip()
            if timeinfo_every_line.count("TotalTime:") > 0:
                # print(meminfo_every_line)
                timeinfo_totletime = timeinfo_every_line.split(":")[1].lstrip().rstrip()
            if timeinfo_every_line.count("WaitTime:") > 0:
                # print(meminfo_every_line)
                timeinfo_waittime = timeinfo_every_line.split(":")[1].lstrip().rstrip()

        time_all=timeinfo_totletime
        print(time_all)
        list = []
        list.append(time_all)
        mem = pandas.DataFrame({"timeinfo": list})
        mem.to_csv("time.csv", index=False, sep=',', mode="a", header=False)


way = performanceTooll()
# way.get_mem()
while 1:
    way.get_time()
    way.get_mem()
    way.get_cpuinfo()
    way.get_batteryinfo()
    time.sleep(3)
















 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值