1、启动时间
冷启动:进程首次创建,并首次加载资源
热启动:非首次启动,在后台运行后,再进行启动
2、获取运行的APP的包名
adb shell logcat | grep "START"
注意:在linux下面,用grep,在windows下面用户findstr
3、冷启动APP
adb shell am start -W -n activity
获取到TotalTime
注意-W,W是大写的
4、冷启动停止app命令
adb shell am force-stop packagenames
5、热启动,停止APP
adb shell input keyevent 3
6、利用python脚本获取启动时间
#/usr/bin/python # -*- coding=utf-8 -*- import os import time import csv class App(object): def __init__(self): self.content="" self.startTime=0 #启动APP def LaunchApp(self): cmd="adb shell am start -W -n activitys" self.content=os.popen(cmd) #启动APP def StopApp(self): cmd='adb shell am force-stop packagenames' os.popen(cmd) #获取启动时间 def GetLaunchedTime(self): for line in self.content.readlines(): if "ThisTime" in line: self.startTime=line.split(":")[1] break return self.startTime #控制类 class Cotroller(object): def __init__(self,count): self.app=App() self.counter=count self.alldata=[("timestamp","elapsedtime")] #单次测试过程 def testprocess(self): self.app.LaunchApp() elapsedtime=self.app.GetLaunchedTime() self.app.StopApp() currentime=self.getCurrentTime() self.alldata.append((currentime,elapsedtime)) #多次执行测试过程 def run(self): while self.counter>0: self.testprocess() self.counter=self.counter-1 #获取当前时间戳 def getCurrentTime(self): currenTime=time.strftime("%Y-%m-%d %H-%M-%S",time.localtime()) return currenTime #数据的存储 def SaveDataToCSV(self): csvfile=file("starttime.csv","wb") writer=csv.writer(csvfile) writer.writerows(self.alldata) csvfile.close() if __name__=="__main__": controller=Cotroller(50) controller.run() controller.SaveDataToCSV()
7、启动时间的均值,和曲线图
8、热启动
#/usr/bin/python # -*- coding=utf-8 -*- import os import time import csv class App(object): def __init__(self): self.content="" self.startTime=0 #启动APP def LaunchApp(self): cmd="adb shell am start -W -n activity" self.content=os.popen(cmd) #启动APP def StopApp(self): cmd='adb shell input keyevent 3' os.popen(cmd) #获取启动时间 def GetLaunchedTime(self): for line in self.content.readlines(): if "ThisTime" in line: self.startTime=line.split(":")[1] break return self.startTime #控制类 class Cotroller(object): def __init__(self,count): self.app=App() self.counter=count self.alldata=[("timestamp","elapsedtime")] #单次测试过程 def testprocess(self): self.app.LaunchApp() elapsedtime=self.app.GetLaunchedTime() self.app.StopApp() currentime=self.getCurrentTime() self.alldata.append((currentime,elapsedtime)) #多次执行测试过程 def run(self): while self.counter>0: self.testprocess() self.counter=self.counter-1 #获取当前时间戳 def getCurrentTime(self): currenTime=time.strftime("%Y-%m-%d %H-%M-%S",time.localtime()) return currenTime #数据的存储 def SaveDataToCSV(self): csvfile=file("starttime1.csv","wb") writer=csv.writer(csvfile) writer.writerows(self.alldata) csvfile.close() if __name__=="__main__": controller=Cotroller(50) controller.run() controller.SaveDataToCSV()
二、cpu的获取方法,脚本实现和数据分析
adb shell dumpsys cpuinfo |grep packagename
在windows下用findstr
#/usr/bin/python # -*- coding=utf-8 -*- import os import time import csv #获取cpu的占比
#控制类 class Cotroller(object): def __init__(self,count): #self.app=App() self.content="" self.counter=count self.alldata=[("timestamp","cpustatus")] #单次测试过程 def testprocess(self): cmd='adb shell dumpsys cpuinfo | grep -e packagenames -e minor' self.content=os.popen(cmd) print "11" print self.content print self.content.readlines() for line in self.content.readlines(): cpuvalue=line.split("%")[0] print cpuvalue currentime=self.getCurrentTime() #print currentime self.alldata.append((currentime,cpuvalue)) #多次执行测试过程 def run(self): while self.counter>0: self.testprocess() self.counter=self.counter-1 time.sleep(5) #获取当前时间戳 def getCurrentTime(self): currenTime=time.strftime("%Y-%m-%d %H-%M-%S",time.localtime()) return currenTime #数据的存储 def SaveDataToCSV(self): csvfile=file("cpuinfo.csv","wb") writer=csv.writer(csvfile) writer.writerows(self.alldata) csvfile.close() if __name__=="__main__": controller=Cotroller(1) controller.run() controller.SaveDataToCSV()