#usr/bin/python
#encoding:utf-8 -*-
import time
import xlwt
import os
def launch_app(package):#启动app,获取启动时间
cmd="adb shell am start -W -n "+package
count=os.popen(cmd)
for line in count.readlines():
if "ThisTime" in line:
launch_time=line.split(':')[1]
break
return launch_time.strip()
file=xlwt.Workbook() #创建表格
table=file.add_sheet("启动时间",cell_overwrite_ok=True)
table.write(0,0,'时间')
table.write(0,1,'启动用时')
table.write(0,2,'单位/s')
list = []
row = 1
if row>0:
while row < 22:
package='com.eebbk.translation/.activity1'
now=launch_app(package)
table.write(row,0,time.strftime('%H:%M:%S',time.localtime()))
table.write(row,1,int(now))
if row > 1:
list.append(int(now))
time.sleep(4)
os.popen('adb shell input keyevent 4')
row += 1
try:
file.save('启动时间测试.xls')
except PermissionError:
pass
time.sleep(3)
print(list)
print("平均值:"+str(sum(list)/len(list)))
print("最小值:"+str(min(list)))
print("最大值:"+str(max(list)))