久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    安卓apk客戶端性能測試

     小豬窩969 2019-12-11

    話不多說,直接上腳本:

    1. 冷熱啟動:

    #/usr/bin/python

    #encoding:utf-8

    import csv

    import os

    import time

    class App(object):

        def __init__(self):

            self.content = ""

            self.startTime = 0

        #啟動App

        def LaunchApp(self):

            print("啟動程序.....")

            cmd = 'adb shell am start -W -n com.android.browser/.BrowserActivity'

            self.content=os.popen(cmd)

        #停止App

        def StopApp(self):

            #冷啟動

            #cmd = 'adb shell am force-stop com.android.browser'

            #熱啟動

            cmd = 'adb shell input keyevent 3'

            print("關(guān)閉程序......")

            os.popen(cmd)

        #獲取啟動時間

        def GetLaunchedTime(self):

            for line in self.content.readlines():

                if "ThisTime" in line:

                    self.startTime = line.split(":")[1].strip()

                    break

            return self.startTime

    #控制類    pasedtime:啟動時間

    class Controller(object):

        def __init__(self, count):

            self.app = App()

            self.counter = count

            self.alldata = [("currenttime", "pasedtime")]

        #單次測試過程

        def testprocess(self):

            self.app.LaunchApp()

            time.sleep(5)

            elpasedtime = self.app.GetLaunchedTime()

            self.app.StopApp()

            time.sleep(3)

            currenttime = self.getCurrentTime()

            self.alldata.append((currenttime, elpasedtime))

        #多次執(zhí)行測試過程

        def run(self):

            while self.counter >0:

                self.testprocess()

                self.counter = self.counter - 1

        #獲取當(dāng)前的時間戳

        def getCurrentTime(self):

            currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            return currentTime

        #數(shù)據(jù)的存儲

        def SaveDataToCSV(self):

            csvfile = open('starttime.csv', 'wb')

            writer = csv.writer(csvfile)

            writer.writerows(self.alldata)

            csvfile.close()

    if __name__ == "__main__":

        controller = Controller(2)

        controller.run()

        controller.SaveDataToCSV()

    2.內(nèi)存:

    #/usr/bin/python

    #encoding:utf-8

    import csv

    import os

    import  time

    """

    請先用命令行運(yùn)行 adb shell top -d num--->(數(shù)字是收取數(shù)據(jù)間隔時間) 收取數(shù)據(jù),并且另存為meminfo

    """

    #控制類

    class Controller(object):

        def __init__(self):

            #定義收集數(shù)據(jù)的數(shù)組 vss:虛擬耗用內(nèi)存(包含共享庫占用的內(nèi)存)  rss:實(shí)際使用物理內(nèi)存(包含共享庫占用的內(nèi)存)

            self.alldata = [("id", "vss", "rss")]

        #分析數(shù)據(jù)

        def analyzedata(self):

            content = self.readfile()

            i = 0

            for line in content:

                if "com.android.browser" in line:

                    print (line)

                    line = "#".join(line.split())

                    vss = line.split("#")[5].strip("K")

                    rss = line.split("#")[6].strip("K")

                    #將獲取到的數(shù)據(jù)存到數(shù)組中

                    self.alldata.append((i, vss, rss))

                    i = i + 1

        #數(shù)據(jù)的存儲

        def SaveDataToCSV(self):

            csvfile = open('meminfo.csv', 'wb')

            writer = csv.writer(csvfile)

            writer.writerows(self.alldata)

            csvfile.close()

        #讀取數(shù)據(jù)文件

        def readfile(self):

            mfile = open("meminfo", "r")

            content = mfile.readlines()

            mfile.close()

            return  content

    if __name__ == "__main__":

        controller = Controller()

        controller.analyzedata()

        controller.SaveDataToCSV()

    3.流量

    #/usr/bin/python

    #encoding:utf-8

    import csv

    import os

    import string

    import time

    #控制類

    class Controller(object):

        def __init__(self, count):

            #定義測試的次數(shù)

            self.counter = count

            #定義收集數(shù)據(jù)的數(shù)組  traffic:總流量

            self.alldata = [("timestamp", "traffic")]

        #單次測試過程

        def testprocess(self):

            #執(zhí)行獲取進(jìn)程的命令

            result = os.popen("y_adb shell ps | findstr com.android.browser")

            #獲取進(jìn)程ID

            pid = result.readlines()[0].split(" ")[4]

            #獲取進(jìn)程ID使用的流量

            traffic = os.popen("y_adb shell cat /proc/"+pid+"/net/dev")

            for line in traffic:

                if "lo" in line:

                    #將所有空行換成#

                    line = "#".join(line.split())

                    #按#號拆分,獲取收到和發(fā)出的流量

                    receive = line.split("#")[1]

                    transmit = line.split("#")[9]

                elif "eth1" in line:

                    # 將所有空行換成#

                    line =  "#".join(line.split())

                    # 按#號拆分,獲取收到和發(fā)出的流量

                    receive2 = line.split("#")[1]

                    transmit2 = line.split("#")[9]

            #計(jì)算所有流量的之和

            alltraffic = string .atoi(receive) + string .atoi(transmit) + string .atoi(receive2) + string .atoi(transmit2)

            #按KB計(jì)算流量值

            alltraffic = alltraffic/1024

            #獲取當(dāng)前時間

            currenttime = self.getCurrentTime()

            #將獲取到的數(shù)據(jù)存到數(shù)組中

            self.alldata.append((currenttime, alltraffic))

        #多次測試過程控制

        def run(self):

            while self.counter >0:

                self.testprocess()

                self.counter = self.counter - 1

                #每5秒鐘采集一次數(shù)據(jù)

                time.sleep(5)

        #獲取當(dāng)前的時間戳

        def getCurrentTime(self):

            currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            return currentTime

        #數(shù)據(jù)的存儲

        def SaveDataToCSV(self):

            csvfile = open('traffic.csv', 'wb')

            writer = csv.writer(csvfile)

            writer.writerows(self.alldata)

            csvfile.close()

    if __name__ == "__main__":

        controller = Controller(2)

        controller.run()

        controller.SaveDataToCSV()

    4.電量

    #/usr/bin/python

    #encoding:utf-8

    import csv

    import os

    import time

    #控制類

    class Controller(object):

        def __init__(self, count):

            #定義測試的次數(shù)

            self.counter = count

            #定義收集數(shù)據(jù)的數(shù)組   power:電量,timestamp:時間

            self.alldata = [("timestamp", "power")]

        #單次測試過程

        def testprocess(self):

            #執(zhí)行獲取電量的命令

            result = os.popen("adb shell dumpsys battery")

            #獲取電量的level

            for line in result:

                if "level" in line:

                    power = line.split(":")[1].strip()

            #獲取當(dāng)前時間

            currenttime = self.getCurrentTime()

            #將獲取到的數(shù)據(jù)存到數(shù)組中

            self.alldata.append((currenttime, power))

        #多次測試過程控制

        def run(self):

            #設(shè)置手機(jī)進(jìn)入非充電狀態(tài)

            os.popen("adb shell dumpsys battery set status 1")

            while self.counter >0:

                self.testprocess()

                self.counter = self.counter - 1

                #每5秒鐘采集一次數(shù)據(jù)

                time.sleep(5)

        #獲取當(dāng)前的時間戳

        def getCurrentTime(self):

            currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            return currentTime

        #數(shù)據(jù)的存儲

        def SaveDataToCSV(self):

            csvfile = open('dianliang.csv', 'wb')

            writer = csv.writer(csvfile)

            writer.writerows(self.alldata)

            csvfile.close()

    if __name__ == "__main__":

        controller = Controller(5)

        controller.run()

        controller.SaveDataToCSV()

    5.cpu

    #/usr/bin/python

    #encoding:utf-8

    import csv

    import os

    import time

    #控制類  cpustatus:cpu利用率

    class Controller(object):

        def __init__(self, count):

            self.counter = count

            self.alldata = [("timestamp", "cpustatus")]

        #單次測試過程

        def testprocess(self):

            result = os.popen("adb shell dumpsys cpuinfo | findstr com.android.browser")

            for line in result.readlines():

                cpuvalue = line.split("%")[0]

                currenttime = self.getCurrentTime()

                self.alldata.append((currenttime,cpuvalue))

                print(self.alldata)

        #多次執(zhí)行測試過程

        def run(self):

            while self.counter >0:

                self.testprocess()

                self.counter = self.counter - 1

                time.sleep(3)

        #獲取當(dāng)前的時間戳

        def getCurrentTime(self):

            currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

            return currentTime

        #數(shù)據(jù)的存儲

        def SaveDataToCSV(self):

            csvfile = open('cpcinfo.csv', 'wb')

            writer = csv.writer(csvfile)

            writer.writerows(self.alldata)

            csvfile.close()

    if __name__ == "__main__":

        controller = Controller(2)

        controller.run()

        controller.SaveDataToCSV()

      本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
      轉(zhuǎn)藏 分享 獻(xiàn)花(0

      0條評論

      發(fā)表

      請遵守用戶 評論公約

      類似文章 更多

      主站蜘蛛池模板: 暖暖 在线 日本 免费 中文| 亚洲国产良家在线观看| 东京热人妻丝袜无码AV一二三区观 | 国内精品久久久久影院优| 欧美人与禽2o2o性论交| 人妻少妇456在线视频| 日本理伦片午夜理伦片| 亚洲色一色噜一噜噜噜| 高清不卡一区二区三区| 中文字幕制服国产精品| 在线A毛片免费视频观看| 4hu44四虎www在线影院麻豆| 精品无码日韩国产不卡AV| 欧美大胆老熟妇乱子伦视频| 四虎永久地址WWW成人久久| 免费无码又爽又刺激软件下载| 亚洲A综合一区二区三区| 国产精品久久久久7777| 欧美国产日产一区二区| 亚洲国产精品综合久久20| 曰韩亚洲AV人人夜夜澡人人爽| 精品视频不卡免费观看| 亚洲综合色婷婷在线观看 | 四川丰满少妇无套内谢| 国产无套粉嫩白浆在线观看| 人妻少妇偷人无码视频| 中文字幕AV无码人妻| 午夜男女爽爽影院免费视频下载| 国产一区日韩二区欧美三区| 精品人无码一区二区三区| 欧美成人一区二区三区不卡| 大地资源中文第二页日本| 欧美乱妇高清无乱码免费| 国产欧美综合在线观看第十页 | 99在线精品国自产拍中文字幕| 国产猛男猛女超爽免费视频| 天堂久久久久VA久久久久| 亚洲成人av综合一区| 思思久久96热在精品国产| 久久久久久久波多野结衣高潮| 欧美成本人视频免费播放|