GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — AndroidPerformanceTest_Python/Test_File.py at master · buildone2011/AndroidPerformanceTest_Python Expand file tree/ Copy pathTest_File.pyMore file actions 164 lines (140 loc) · 5.06 KB / Copy pathTest_File.pyFile metadata and controls164 lines (140 loc) · 5.06 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 # -*- coding: utf-8 -*- import os, re,sys import subprocess import time, os, sched,shlex,threading from reportlab.graphics.shapes import * from reportlab.graphics.charts.lineplots import LinePlot from reportlab.graphics.charts.textlabels import Label from reportlab.graphics import renderPDF # execute command, and return the output def execCmd(cmd): r = os.popen(cmd) text = r.read() r.close() return text def readShellBack(): popen = subprocess.Popen(['adb', 'logcat'], stdout = subprocess.PIPE) while True: print popen.stdout.readline() def catchException(): try: readShellBack() except KeyboardInterrupt: print execCmd('adb devices') def getAppPID(packagename): appPID_list = [] args = shlex.split('adb shell top') popen = subprocess.Popen(args,stdout = subprocess.PIPE) Status = True try: while Status: logcat = popen.stdout.readline() if packagename in logcat: Status=False for pid in logcat.split(' '): if pid.isalnum(): print pid return pid except KeyboardInterrupt: return pid def getGCfile(): os.system("adb kill-server") os.system("adb devices") print '日志正在记录中' try: os.system("adb logcat -v time -v threadtime *:D | grep GC>GCFile.txt") except KeyboardInterrupt: print 'GC logcat is over' def MakePDF(times,list,reportname,pdfname): drawing = Drawing(500,300) lp = LinePlot() lp.x = 50 lp.y = 50 lp.height = 125 lp.width = 300 lp.data = [zip(times, list)] lp.lines[0].strokeColor = colors.blue lp.lines[1].strokeColor = colors.red lp.lines[2].strokeColor = colors.green drawing.add(lp) drawing.add(String(350,150, reportname,fontSize=14,fillColor=colors.red)) renderPDF.drawToFile(drawing,pdfname,reportname) def analysisGCFile(AppPID): GC_Freed =0 GC_Freed_All =0 GC_per =0 GC_per_all =0 GC_time = 0 GC_time_all =0 GC_Freed_list = [] GC_per_list = [] GC_time_list = [] GC_count_list = [] GC_count =0 for data in open('GCFile.txt'): for i in data.split(' '): if AppPID == i and 'freed' in data: GC_Freed = int(filter(str.isdigit,data.split(' ')[(data.split(' ').index('freed'))+1])) GC_Freed_list.append(GC_Freed) GC_Freed_All = GC_Freed_All+GC_Freed GC_per = int(filter(str.isdigit,data.split(' ')[(data.split(' ').index('freed'))+2])) GC_per_list.append(GC_per) GC_per_all = GC_per_all+GC_per number1 = data.split(' ')[(data.split(' ').index('freed'))+8] if '+' in number1: GC_time = int(filter(str.isdigit,number1.split('+')[0]))+int(filter(str.isdigit,number1.split('+')[1])) GC_time_all=GC_time_all+GC_time GC_time_list.append(GC_time) else: GC_time = int(number1[:-4]) GC_time_all=GC_time_all+GC_time GC_time_list.append(GC_time) print GC_time GC_count = GC_count+1 GC_count_list.append(GC_count) average_GC_Freed = '%.2f'%float(GC_Freed_All/GC_count) average_GC_per = '%.2f'%float(GC_per_all/GC_count) average_GC_time = '%.2f'%float(GC_time_all/GC_count) print GC_Freed_list,average_GC_Freed,GC_count_list,GC_per_list,average_GC_per,GC_time_list,average_GC_time return GC_Freed_list,average_GC_Freed,GC_count_list,GC_per_list,average_GC_per,GC_time_list,average_GC_time def analysisTrafficFile(packagename): TrafficDataList=[] TrafficDataList2=[] TrafficCount =0 TrafficCountList =[] for data in open('NetWorkFile.txt'): if packagename in data: TrafficDataList.append(int(data.split(' ')[len(data.split(' '))-1])) TrafficCount =TrafficCount+1 TrafficCountList.append(TrafficCount) for i in TrafficDataList: TrafficDataList2.append(float(i-TrafficDataList[0])/1024) return TrafficCountList,TrafficDataList2 def WriteLog(waittime): try: subprocess.Popen("adb logcat -v time -v threadtime *:D | grep GC>GCFile.txt",shell=True) subprocess.Popen("adb logcat -v time *:E | grep Python2Android>NetWorkFile.txt",shell=True) print '日志正在记录中。。。请稍后' time.sleep(float(waittime)*3600) except KeyboardInterrupt: print '报告正在生成' os.system('adb kill-server') schedule = sched.scheduler(time.time, time.sleep) def perform_command(cmd, inc): os.system(cmd) def timming_exe(cmd, inc = 60): # enter用来安排某事件的发生时间,从现在起第n秒开始启动 schedule.enter(inc, 0, perform_command, (cmd, inc)) # 持续运行,直到计划时间队列变成空为止 schedule.run() #timming_exe("echo %time%", 10) if __name__=="__main__": app_pid = getAppPID(sys.argv[1]) WriteLog(sys.argv[2]) TrafficCountList,TrafficDataList = analysisTrafficFile(sys.argv[1]) print TrafficCountList,TrafficDataList,'xxxx' MakePDF(TrafficCountList,TrafficDataList,'average Traffic:'+'kb',"流量消耗.pdf") GC_Freed_list,average_GC_Freed,GC_count_list,GC_per_list,average_GC_per,GC_time_list,average_GC_time= analysisGCFile(app_pid) MakePDF(GC_count_list,GC_Freed_list,'average GC Freed:'+str(average_GC_Freed)+'kb',"GC_Freed报告.pdf") MakePDF(GC_count_list,GC_per_list,'average GC per:'+str(average_GC_per)+'%',"GC_百分比报告.pdf") MakePDF(GC_count_list,GC_per_list,'average GC time:'+str(average_GC_time)+'ms',"GC_时间消耗.pdf") |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |