# 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)