def start(devicess): devices = devicess["devices"] print(devices) num = devicess["num"] app = {} dev_obj = BaseMonitor.init_dev(devices) BaseMonitor.install_apk(dev_obj, "./install", configData.package_name) print(devices, app, num) mkdirInit(dev_obj, app, num) mc = {} # monkey开始测试 currTime = time.strftime("%Y%m%d%H%M%S", time.localtime()) mc["log"] = PATH("./log") + "/" mc["monkey_log"] = f"{mc['log']}{currTime}_{dev_obj.uuid}_monkey.log" mc["cmd"] = configData.cmd + " >> " + mc["monkey_log"] start_monkey("adb -s " + dev_obj.uuid + " shell " + mc["cmd"], mc["log"], currTime, dev_obj.uuid) time.sleep(1) starttime = datetime.datetime.now() # pid = BaseMonitor.get_pid(dev_obj, configData.package_name) cpu_kel = BaseMonitor.get_phone_Kernel(dev_obj)["cpu_sum"] # print(cpu_kel) beforeBattery = BaseMonitor.get_battery(dev_obj) while True: with open(mc["monkey_log"], encoding='utf-8') as monkeylog: time.sleep(1) # 每1秒采集检查一次 pid = BaseMonitor.get_pid(dev_obj, configData.package_name) BaseMonitor.cpu_rate(dev_obj, pid, cpu_kel) BaseMonitor.get_mem(dev_obj, configData.package_name) BaseMonitor.get_fps(dev_obj, configData.package_name) BaseMonitor.get_flow(dev_obj, pid, configData.net) BaseMonitor.get_battery(dev_obj) if monkeylog.read().count('Monkey finished') > 0: endtime = datetime.datetime.now() print(str(devices) + "测试完成咯") writeSum(1, path=PATH("./info/sumInfo.pickle")) app[devices]["header"]["beforeBattery"] = beforeBattery app[devices]["header"][ "afterBattery"] = BaseMonitor.get_battery(dev_obj) app[devices]["header"]["net"] = configData.net app[devices]["header"]["monkey_log"] = mc["monkey_log"] app[devices]["header"]["time"] = str( (endtime - starttime).seconds) basePath = f"./info/{dev_obj.uuid}_" monkeyLog = PATH(f"{basePath}monkeyLog.pickle") app[devices]["monkeyLog"] = monkeyLog writeInfo(app, PATH("./info/info.pickle")) break # go.info[devices]["header"]["sumTime"] = str((endtime - starttime).seconds) + "秒" # report(go.info) if readInfo(PATH("./info/sumInfo.pickle")) <= 0: print(readInfo(PATH("./info/info.pickle"))) report_excel(readInfo(PATH("./info/info.pickle")))
def report_html(): dataFile = readInfo("./info/info.pickle") data = dataAnalysis(dataFile) monkeyLog = monkeyLogAnalysis(data) detial = line_detial_grid(cpu=data[1], memory=data[2], upFlow=data[3], downFlow=data[4], fps=data[5], battery=data[6]) tab = Tab() tab.add(table_base(data[0]), "汇总信息") tab.add(detial, "详细信息") tab.add(table_traces(monkeyLog), "日志记录") tab.render(f"./report/monkey/monkeyTestReport_{currTime}.html")
def monitor(self, info): worksheet = self.wd.add_worksheet("Analysis") worksheet.set_column("A:A", 15) worksheet.set_column("B:B", 10) worksheet.set_column("C:C", 10) worksheet.set_column("D:D", 10) worksheet.set_column("E:E", 10) worksheet.set_column("F:F", 10) worksheet.set_column("G:G", 10) worksheet.set_column("H:H", 10) worksheet.set_column("I:I", 10) worksheet.set_column("J:J", 10) worksheet.set_column("K:K", 10) worksheet.set_column("L:L", 10) worksheet.set_column("L:L", 10) worksheet.set_column("M:M", 10) worksheet.set_column("N:N", 10) worksheet.set_column("O:O", 10) worksheet.set_column("P:P", 10) worksheet.set_column("Q:Q", 10) worksheet.set_column("R:R", 10) worksheet.set_row(1, 30) worksheet.set_row(2, 30) worksheet.set_row(3, 30) worksheet.set_row(4, 30) worksheet.set_row(5, 30) worksheet.set_row(6, 30) worksheet.set_row(7, 30) worksheet.set_row(8, 30) worksheet.set_row(9, 30) worksheet.set_row(10, 30) worksheet.set_row(11, 30) worksheet.set_row(12, 30) define_format_H1 = get_format(self.wd, {'bold': True, 'font_size': 18}) define_format_H2 = get_format(self.wd, {'bold': True, 'font_size': 14}) define_format_H1.set_border(1) define_format_H2.set_border(1) define_format_H1.set_align("center") define_format_H2.set_align("center") define_format_H2.set_bg_color("blue") define_format_H2.set_color("#ffffff") worksheet.merge_range('A1:L1', 'monkey性能监控', define_format_H1) _write_center(worksheet, "A2", '设备名', self.wd) _write_center(worksheet, "B2", 'CPU', self.wd) _write_center(worksheet, "C2", '内存', self.wd) _write_center(worksheet, "D2", '分辨率', self.wd) _write_center(worksheet, "E2", '网络', self.wd) _write_center(worksheet, "F2", "耗时", self.wd) _write_center(worksheet, "G2", "CPU峰值", self.wd) _write_center(worksheet, "H2", "CPU均值", self.wd) _write_center(worksheet, "I2", "内存峰值", self.wd) _write_center(worksheet, "J2", "内存均值", self.wd) _write_center(worksheet, "K2", "fps峰值", self.wd) _write_center(worksheet, "L2", "fps均值", self.wd) _write_center(worksheet, "M2", "电量测试之前", self.wd) _write_center(worksheet, "N2", "电量测试之后", self.wd) _write_center(worksheet, "O2", "上行流量峰值", self.wd) _write_center(worksheet, "P2", "上行流量均值", self.wd) _write_center(worksheet, "Q2", "下行流量峰值", self.wd) _write_center(worksheet, "R2", "下行流量均值", self.wd) temp = 3 for t in info: for wrap in t: for item in t[wrap]: self.getCrashMsg(t[wrap]["header"]["monkey_log"]) _write_center(worksheet, "A" + str(temp), t[wrap]["header"]["phone_name"], self.wd) _write_center(worksheet, "B" + str(temp), str(t[wrap]["header"]["kel"]) + "核", self.wd) _write_center( worksheet, "C" + str(temp), str(math.ceil(int(t[wrap]["header"]["rom"]) / 1024)) + "M", self.wd) _write_center(worksheet, "D" + str(temp), t[wrap]["header"]["pix"], self.wd) _write_center(worksheet, "E" + str(temp), t[wrap]["header"]["net"], self.wd) _write_center(worksheet, "F" + str(temp), t[wrap]["header"]["time"], self.wd) cpu = readInfo(t[wrap]["cpu"]) men = readInfo(t[wrap]["men"]) fps = readInfo(t[wrap]["fps"]) flow = readInfo(t[wrap]["flow"]) print("----wrap-----") print(flow) _write_center(worksheet, "G" + str(temp), BaseAnalysis.maxCpu(cpu), self.wd) _write_center(worksheet, "H" + str(temp), BaseAnalysis.avgCpu(cpu), self.wd) _write_center(worksheet, "I" + str(temp), BaseAnalysis.maxMen(men), self.wd) _write_center( worksheet, "J" + str(temp), BaseAnalysis.avgMen(men, int(t[wrap]["header"]["rom"])), self.wd) _write_center(worksheet, "K" + str(temp), BaseAnalysis.maxFps(fps), self.wd) _write_center(worksheet, "L" + str(temp), BaseAnalysis.avgFps(fps), self.wd) _write_center(worksheet, "M" + str(temp), t[wrap]["header"]["beforeBattery"], self.wd) _write_center(worksheet, "N" + str(temp), t[wrap]["header"]["afterBattery"], self.wd) _maxFlow = BaseAnalysis.maxFlow(flow) _avgFLow = BaseAnalysis.avgFlow(flow) print("-----_maxFlow----------") print(_maxFlow) _write_center(worksheet, "O" + str(temp), _maxFlow[0], self.wd) _write_center(worksheet, "Q" + str(temp), _maxFlow[1], self.wd) _write_center(worksheet, "P" + str(temp), _avgFLow[1], self.wd) _write_center(worksheet, "R" + str(temp), _avgFLow[1], self.wd) break temp = temp + 1
def analysis(self, info): for t in info: for wrap in t: name = wrap.split(":")[0] + "detail" # sheet名字 print(f"name: {name}") worksheet = self.wd.add_worksheet(name) worksheet.set_column("A:A", 10) worksheet.set_column("B:B", 10) worksheet.set_column("C:C", 10) worksheet.set_column("D:D", 10) worksheet.set_column("E:E", 10) worksheet.set_column("F:F", 10) worksheet.set_row(1, 30) worksheet.set_row(2, 30) worksheet.set_row(3, 30) worksheet.set_row(4, 30) worksheet.set_row(5, 30) worksheet.set_row(6, 30) define_format_H1 = get_format(self.wd, { 'bold': True, 'font_size': 18 }) define_format_H2 = get_format(self.wd, { 'bold': True, 'font_size': 14 }) define_format_H1.set_border(1) define_format_H2.set_border(1) define_format_H1.set_align("center") define_format_H2.set_align("center") define_format_H2.set_bg_color("blue") define_format_H2.set_color("#ffffff") _write_center(worksheet, "A1", 'cpu(%)', self.wd) _write_center(worksheet, "B1", 'men(M)', self.wd) _write_center(worksheet, "C1", 'fps', self.wd) _write_center(worksheet, "D1", 'battery(%)', self.wd) _write_center(worksheet, "E1", '上行流量(KB)', self.wd) _write_center(worksheet, "F1", '下行流量(KB)', self.wd) for item in t[wrap]: print("------data-----") temp = 2 cpu = readInfo(t[wrap]["cpu"]) for item in cpu: _write_center(worksheet, "A" + str(temp), float("%.1f" % item) * 10, self.wd) temp = temp + 1 temp = 2 men = readInfo(t[wrap]["men"]) for item in men: _write_center(worksheet, "B" + str(temp), math.ceil(item / 1024), self.wd) temp = temp + 1 temp = 2 fps = readInfo(t[wrap]["fps"]) for item in fps: _write_center(worksheet, "C" + str(temp), item, self.wd) temp = temp + 1 temp = 2 battery = readInfo(t[wrap]["battery"]) for item in battery: _write_center(worksheet, "D" + str(temp), item, self.wd) temp = temp + 1 print("!!!!!!!!" * 10) print("!!!!!!!!" * 10) print("!!!!!!!!" * 10) print("!!!!!!!!" * 10) temp = 2 flow = readInfo(t[wrap]["flow"]) for item in flow[0]: if item > 0: _write_center(worksheet, "E" + str(temp), math.ceil(item / 1024), self.wd) else: _write_center(worksheet, "E" + str(temp), 0, self.wd) temp = temp + 1 temp = 2 for item in flow[1]: if item > 0: _write_center(worksheet, "F" + str(temp), math.ceil(item / 1024), self.wd) else: _write_center(worksheet, "F" + str(temp), 0, self.wd) temp = temp + 1 self.plot(worksheet, "cpu", len(cpu), name) self.plot(worksheet, "men", len(men), name) self.plot(worksheet, "battery", len(battery), name) self.plot(worksheet, "fps", len(fps), name) self.plot(worksheet, "flowUp", len(flow[0]), name) self.plot(worksheet, "flowDown", len(flow[1]), name) break
'/Users/xxxxxxxxx/workspace/github/airTest_monkey/info/192.168.20.29:5556_battery.pickle', 'men': '/Users/xxxxxxxxx/workspace/github/airTest_monkey/info/192.168.20.78:5555_men.pickle', 'flow': '/Users/xxxxxxxxx/workspace/github/airTest_monkey/info/192.168.20.29:5556_flow.pickle', 'header': { 'rom': 770300, 'kel': '2核', 'monkey_log': '/Users/xxxxxxxxx/workspace/github/airTest_monkey/log/20200310115902_192.168.20.29:5556_monkey.log', 'beforeBattery': 99, 'pix': '1440x810', 'time': '10秒', 'afterBattery': 99, 'phone_name': 'GT-I9500_samsung_4.4', 'net': 'gprs' }, 'fps': '/Users/xxxxxxxxx/workspace/github/airTest_monkey/info/192.168.20.78:5555_fps.pickle' } }] tem = OperateReport(workbook) tem.monitor(info) tem.analysis(info) tem.crash() tem.close() dataFile = readInfo("../info/info.pickle") print(dataFile)