def run(self): """ 基于UID获取App的网络流量的方法 从/proc/net/xt_qtaguid/stats获取网络流量统计,进行判断 """ while True: if utils.stop != True: break sleep(1) totalNet = [] flag_net = utils.shell( "cat /proc/net/xt_qtaguid/stats").stdout.readline() if "No such file or directory" not in flag_net: list_rx = [] # 接收网络数据流量列表 list_tx = [] # 发送网络数据流量列表 str_uid_net_stats = utils.shell( "cat /proc/net/xt_qtaguid/stats|findstr %s" % utils.app_uid(self.pkg)).stdout.readlines() try: for item in str_uid_net_stats: rx_bytes = item.split()[5] # 接收网络数据流量 tx_bytes = item.split()[7] # 发送网络数据流量 list_rx.append(int(rx_bytes)) list_tx.append(int(tx_bytes)) tm = utils.timestamp() floatTotalNetTraffic = (sum(list_rx) + sum(list_tx)) / 1024.0 / 1024.0 floatTotalNetTraffic = round(floatTotalNetTraffic, 2) # print "接受:", list_rx # print "发送:", list_tx # print "总消耗:%sKB" % floatTotalNetTraffic totalNet.append(floatTotalNetTraffic) totalNet.insert(0, tm) self.ls.append(totalNet) except: print "[ERROR]: cannot get the /proc/net/xt_qtaguid/stats" return 0.0 else: strTotalTxBytes = utils.shell( "cat proc/uid_stat/%s/tcp_snd" % utils.app_uid(self.pkg)).stdout.readline() strTotalRxBytes = utils.shell( "cat proc/uid_stat/%s/tcp_rcv" % utils.app_uid(self.pkg)).stdout.readline() try: tm = utils.timestamp() floatTotalTraffic = ( int(strTotalTxBytes) + int(strTotalRxBytes)) / 1024.0 / 1024.0 floatTotalTraffic = round(floatTotalTraffic, 2) # print "总消耗:%sKB" % floatTotalTraffic totalNet.append(floatTotalTraffic) totalNet.insert(0, tm) self.ls.append(totalNet) except: return 0.0
def run(self): user = utils.shell( "su -c 'ls'").stdout.readline() # 检查手机是否可以ROOT用户执行命令 if "not found" in user: # 非ROOT手机执行该方式 serial_number = utils.get_serialno() command = android_commands.AndroidCommands(serial_number) collector = surface_stats_collector.SurfaceStatsCollector(command) collector.DisableWarningAboutEmptyData() collector.Start() while True: if utils.stop != True: break tm = utils.timestamp() results = collector.SampleResults() fpsdata = [] if not results: pass else: for i in results: if i.name == "avg_surface_fps": if i.value == None: fpsdata.insert(0, tm) fpsdata.append(0) else: fpsdata.insert(0, tm) fpsdata.append(i.value) self.ls.append(fpsdata) collector.Stop() else: # ROOT手机执行该方式 value1 = self.get_frame_data() self.time_before = value1["timestamp"] self.surface_before = value1["surface"] while True: if utils.stop != True: break y = [] time.sleep(1) value2 = self.get_frame_data() self.time_after = value2["timestamp"] self.surface_after = value2["surface"] time_difference = int( round((self.time_after - self.time_before), 2)) frame_count = (self.surface_after - self.surface_before) tm = utils.timestamp() fps = int(frame_count / time_difference) y.append(fps) self.time_before = self.time_after self.surface_before = self.surface_after y.insert(0, tm) self.ls.append(y)
def run(self): """ 基于UID获取App的网络流量的方法 从/proc/net/xt_qtaguid/stats获取网络流量统计,进行判断 """ while True: if utils.stop!=True: break sleep(1) totalNet = [] flag_net = utils.shell("cat /proc/net/xt_qtaguid/stats").stdout.readline() if "No such file or directory" not in flag_net: list_rx = [] # 接收网络数据流量列表 list_tx = [] # 发送网络数据流量列表 str_uid_net_stats = utils.shell( "cat /proc/net/xt_qtaguid/stats|findstr %s" % utils.get_app_uid( self.pkg)).stdout.readlines() try: for item in str_uid_net_stats: rx_bytes = item.split()[5] # 接收网络数据流量 tx_bytes = item.split()[7] # 发送网络数据流量 list_rx.append(int(rx_bytes)) list_tx.append(int(tx_bytes)) tm = utils.timestamp() floatTotalNetTraffic = (sum(list_rx) + sum(list_tx)) / 1024.0 / 1024.0 floatTotalNetTraffic = round(floatTotalNetTraffic, 2) # print "接受:", list_rx # print "发送:", list_tx # print "总消耗:%sKB" % floatTotalNetTraffic totalNet.append(floatTotalNetTraffic) totalNet.insert(0, tm) self.ls.append(totalNet) except: print "[ERROR]: cannot get the /proc/net/xt_qtaguid/stats" return 0.0 else: strTotalTxBytes = utils.shell( "cat proc/uid_stat/%s/tcp_snd" % utils.get_app_uid(self.pkg)).stdout.readline() strTotalRxBytes = utils.shell( "cat proc/uid_stat/%s/tcp_rcv" % utils.get_app_uid(self.pkg)).stdout.readline() try: tm = utils.timestamp() floatTotalTraffic = (int(strTotalTxBytes) + int(strTotalRxBytes)) / 1024.0 / 1024.0 floatTotalTraffic = round(floatTotalTraffic, 2) # print "总消耗:%sKB" % floatTotalTraffic totalNet.append(floatTotalTraffic) totalNet.insert(0, tm) self.ls.append(totalNet) except: return 0.0
def get_crash_log(time_list): log_file = PATH("%s/crash_log/%s.txt" % (os.getcwd(), utils.timestamp())) f = open(log_file, "w") for time in time_list: cash_log = utils.shell("dumpsys dropbox --print %s" % time).stdout.read() f.write(cash_log) f.close()
def get_crash_log(time_list): log_file = PATH("%s/crash_log/%s.txt" % (os.getcwd(), utils.timestamp())) f = open(log_file, "w") for time in time_list: cash_log = utils.shell("dumpsys dropbox --print %s" % time).stdout.read() f.write(cash_log) f.close()
def screenshot(): path = PATH("%s/screenshot" %os.getcwd()) utils.shell("screencap -p /data/local/tmp/tmp.png").wait() if not os.path.isdir("%s/screenshot" %PATH(os.getcwd())): os.makedirs(path) utils.adb("pull /data/local/tmp/tmp.png %s" %PATH("%s/%s.png" %(path, utils.timestamp()))).wait() utils.shell("rm /data/local/tmp/tmp.png")
def line_chart(): data = top() cpu_data = [] mem_data = [] #去掉cpu占用率中的百分号,并转换为int型 print "------------" for cpu in data[0]: cpu_data.append(string.atoi(cpu.split("%")[0])) #去掉内存占用中的单位K,并转换为int型,以M为单位 for mem in data[1]: mem_data.append(string.atof(mem.split("K")[0])/1024) #横坐标 labels = [] for i in range(1, times + 1): labels.append(str(i)) #自动设置图表区域宽度 if times <= 50: xArea = times * 40 elif 50 < times <= 90: xArea = times * 20 else: xArea = 1800 c = XYChart(xArea, 800, 0xCCEEFF, 0x000000, 1) c.setPlotArea(60, 100, xArea - 100, 650) c.addLegend(50, 30, 0, "arialbd.ttf", 15).setBackground(Transparent) c.addTitle("cpu and memery info(%s)" %pkg_name, "timesbi.ttf", 15).setBackground(0xCCEEFF, 0x000000, glassEffect()) c.yAxis().setTitle("The numerical", "arialbd.ttf", 12) c.xAxis().setTitle("Times", "arialbd.ttf", 12) c.xAxis().setLabels(labels) #自动设置X轴步长 if times <= 50: step = 1 else: step = times / 50 + 1 c.xAxis().setLabelStep(step) layer = c.addLineLayer() layer.setLineWidth(2) layer.addDataSet(cpu_data, 0xff0000, "cpu(%)") layer.addDataSet(mem_data, 0x008800, "mem(M)") path = PATH("%s/chart" %os.getcwd()) if not os.path.isdir(path): os.makedirs(path) #图片保存至脚本当前目录的chart目录下 c.makeChart(PATH("%s/%s.png" %(path, utils.timestamp())))
def line_chart(): data = top() cpu_data = [] mem_data = [] # 去掉cpu占用率中的百分号,并转换为int型 for cpu in data[0]: cpu_data.append(string.atoi(cpu.split("%")[0])) # 去掉内存占用中的单位K,并转换为int型,以M为单位 for mem in data[1]: mem_data.append(string.atof(mem.split("K")[0]) / 1024) # 横坐标 labels = [] for i in range(1, times + 1): labels.append(str(i)) # 自动设置图表区域宽度 if times <= 50: xArea = times * 40 elif 50 < times <= 90: xArea = times * 20 else: xArea = 1800 c = XYChart(xArea, 800, 0xCCEEFF, 0x000000, 1) c.setPlotArea(60, 100, xArea - 100, 650) c.addLegend(50, 30, 0, "arialbd.ttf", 15).setBackground(Transparent) c.addTitle("cpu and memery info(%s)" % pkg_name, "timesbi.ttf", 15).setBackground(0xCCEEFF, 0x000000, glassEffect()) c.yAxis().setTitle("The numerical", "arialbd.ttf", 12) c.xAxis().setTitle("Times", "arialbd.ttf", 12) c.xAxis().setLabels(labels) # 自动设置X轴步长 if times <= 50: step = 1 else: step = times / 50 + 1 c.xAxis().setLabelStep(step) layer = c.addLineLayer() layer.setLineWidth(2) layer.addDataSet(cpu_data, 0xff0000, "cpu(%)") layer.addDataSet(mem_data, 0x008800, "mem(M)") path = PATH("%s/chart" % os.getcwd()) if not os.path.isdir(path): os.makedirs(path) # 图标保存至脚本当前目录的chart目录下 c.makeChart(PATH("%s/%s.png" % (path, utils.timestamp())))
def __init__(self): """ 初始化一个工作薄 :return: """ self.__workbook = xlsxwriter.Workbook( "{location}{time} {device}.xlsx".format(location="./chart/", time=utils.timestamp(), device=utils.get_device_name()), {'strings_to_numbers': True}) self.format = self.__workbook.add_format({'num_format': 'yyyy-mm-dd %H.%M.%S'}) self.format_head = self.__workbook.add_format({'bold': True})
def run(self): while True: if utils.stop!=True: break sleep(1) y = [] tm = utils.timestamp() result = utils.shell("cat /sys/class/thermal/thermal_zone0/temp").stdout.readline() if "No such file or directory" in result: result = 0 y.append(tm) y.append("".join(list(result)[0:2])+"."+"".join(list(result)[2:])) self.ls.append(y)
def write_csv(*list): path = PATH("{}/fps_data".format(os.getcwd())) if not os.path.isdir(path): os.makedirs(path) f = open(PATH("%s/fps-%s.csv" %(path, utils.timestamp())), "w") times = list[0] fps = list[1] jankniess = list[2] for i in xrange(0, len(fps) - 1): f.write("{0},{1},{2},\n".format(str(times[i]), str(fps[i]), str(jankniess[i]))) f.close()
def record(): utils.shell("screenrecord /data/local/tmp/video.mp4") input_key = raw_input("Please press the Enter key to stop recording:\n") if input_key == "": utils.adb("kill-server") print "Get Video file..." path = PATH("%s/video" %os.getcwd()) if not os.path.isdir(path): os.makedirs(path) utils.adb("pull /data/local/tmp/video.mp4 %s" %PATH("%s/%s.mp4" %(path, utils.timestamp()))).wait()
def record(): utils.shell("screenrecord /data/local/tmp/video.mp4") input_key = raw_input("Please press the Enter key to stop recording:\n") if input_key == "": utils.adb("kill-server") print "Get Video file..." path = PATH("%s/video" %os.getcwd()) if not os.path.isdir(path): os.makedirs(path) utils.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, utils.timestamp()))).wait()
def __init__(self): """ 初始化一个工作薄 :return: """ self.__workbook = xlsxwriter.Workbook( "{location}{time} {device}.xlsx".format( location="./chart/", time=utils.timestamp(), device=utils.get_device_name()), {'strings_to_numbers': True}) self.format = self.__workbook.add_format( {'num_format': 'yyyy-mm-dd %H.%M.%S'}) self.format_head = self.__workbook.add_format({'bold': True})
def run(self): while True: if utils.stop != True: break sleep(1) y = [] tm = utils.timestamp() result = utils.shell( "cat /sys/class/thermal/thermal_zone0/temp").stdout.readline() if "No such file or directory" in result: result = 0 y.append(tm) y.append("".join(list(result)[0:2]) + "." + "".join(list(result)[2:])) self.ls.append(y)
def run(self): while True: if utils.stop!=True: break sleep(1) y = [] dictionaries = {} tm = utils.timestamp() result = utils.shell("dumpsys battery").stdout.readlines() for i in result[1:]: new = i.split(":") dictionaries[new[0].strip()] = new[1].strip() y.append(tm) y.append("".join(list(dictionaries["temperature"])[0:2])+"."+"".join(list(dictionaries["temperature"])[2:])) self.ls.append(y)
def run(self): mem_command = "dumpsys meminfo %s|gawk '/MEMINFO/,/App Summary/'|grep TOTAL|gawk '{print $2,$3,$4,$5,$6,$7,$8}'" % self.pkg while True: if utils.stop != True: break sleep(1) y = [] tm = utils.timestamp() results = utils.shell(mem_command).stdout.readline().split() # print "内存:%s" % results y.append(tm) for index in results: y.append(index) self.ls.append(y)
def run(self): self.total_before = self.get_total_cpu_time() self.process_before = self.get_process_cpu_time() while True: if utils.stop != True: break y = [] sleep(1) tm = utils.timestamp() self.total_after = self.get_total_cpu_time() self.process_after = self.get_process_cpu_time() usage = str( round(float(self.process_after - self.process_before) / float(self.total_after - self.total_before), 4) * 100) y.append(tm) y.append(usage) # print "CPU占用率:%s\n" % usage self.total_before = self.total_after self.process_before = self.process_after self.ls.append(y)
def run(self): self.total_before = self.get_total_cpu_time() self.process_before = self.get_process_cpu_time() while True: if utils.stop != True: break y = [] sleep(1) tm = utils.timestamp() self.total_after = self.get_total_cpu_time() self.process_after = self.get_process_cpu_time() usage = str( round( float(self.process_after - self.process_before) / float(self.total_after - self.total_before), 4) * 100) y.append(tm) y.append(usage) # print "CPU占用率:%s\n" % usage self.total_before = self.total_after self.process_before = self.process_after self.ls.append(y)
try: _limit_time = int(limit_time) + 1 except: record() if 0 < _limit_time <= 180: utils.shell("screenrecord --time-limit %s /data/local/tmp/video.mp4" % limit_time).wait() else: print "Please set again!" record() if __name__ == "__main__": sdk = string.atoi( utils.shell("getprop ro.build.version.sdk").stdout.read()) if sdk < 19: print "sdk version is %s, less than 19!" sys.exit(0) else: record() print "Get Video file..." time.sleep(3) path = PATH("%s/video" % os.getcwd()) if not os.path.isdir(path): os.makedirs(path) utils.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, utils.timestamp()))) print "Completed"
if input_key == "": utils.adb("kill-server") print "Get Video file..." <<<<<<< HEAD <<<<<<< HEAD path = PATH("%s/video" % os.getcwd()) ======= ======= >>>>>>> upstream/master utils.adb("start-server") time.sleep(1.5) path = PATH("%s/video" %os.getcwd()) >>>>>>> upstream/master if not os.path.isdir(path): os.makedirs(path) utils.adb("pull /data/local/tmp/video.mp4 %s" % PATH("%s/%s.mp4" % (path, utils.timestamp()))).wait() if __name__ == "__main__": sdk = string.atoi(utils.shell("getprop ro.build.version.sdk").stdout.read()) if sdk < 19: print "sdk version is %s, less than 19!" sys.exit(0) else: record() print "Completed"