def get_cpuModel(self): print( "CPU型号:", utils.shell("cat /proc/cpuinfo|findstr Hardware").stdout.readline( ).strip().split(":")[1]) return utils.shell("cat /proc/cpuinfo|findstr Hardware" ).stdout.readline().strip().split(":")[1]
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().decode('UTF-8') 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() print("xxxxxx", str_uid_net_stats) 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) print(self.ls) 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_sdkVersion(self): print( "SDK版本:", utils.shell("cat /system/build.prop | findstr ro.build.version.sdk" ).stdout.readline().split("=")[1]) return utils.shell( "cat /system/build.prop | findstr ro.build.version.sdk" ).stdout.readline().split("=")[1]
def get_process_cpu_time(self): ''' pid 进程号 utime 该任务在用户态运行的时间,单位为jiffies stime 该任务在核心态运行的时间,单位为jiffies cutime 所有已死线程在用户态运行的时间,单位为jiffies cstime 所有已死在核心态运行的时间,单位为jiffies ''' utime = stime = cutime = cstime = 0 time = utils.shell("cat /proc/%s/stat" % self.get_pid()).stdout.readline().split() pro_time = 0 utime = time[13].decode() stime = time[14].decode() cutime = time[15].decode() cstime = time[16].decode() print("utime=" + utime) print("stime=" + stime) print("cutime=" + cutime) print("cstime=" + cstime) pro_time = int(utime) + int(stime) + int(cutime) + int(cstime) print("processCpuTime=" + str(pro_time)) # for i in time: # pro_time += int(i) return pro_time
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_frame_data(self): """ 获取帧数据及时间戳 :return:字典 """ result = utils.shell("su -c 'service call SurfaceFlinger 1013'" ).stdout.readline().decode('UTF-8') cur_surface = int(result.split("(")[1].split()[0], 16) return {"surface": cur_surface, "timestamp": time.time()}
def run(self): user = utils.shell("su -c 'ls'").stdout.readline().decode( 'UTF-8') # 检查手机是否可以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() results = 'NO RooT' 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) print("refresh:%ss " % time_difference, "FPS:%s" % fps)
def get_crash_time_list(): time_list = [] result_list = utils.shell("dumpsys dropbox | %s data_app_crash" % utils.find_util).stdout.readlines() for time in result_list: temp_list = time.split(" ") temp_time = [] temp_time.append(temp_list[0]) temp_time.append(temp_list[1]) time_list.append(" ".join(temp_time)) return time_list
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()).decode('UTF-8') if "No such file or directory" in result: result = 0 y.append(tm) logging.debug("CPU温度:%s", result) y.append("".join(list(result)[0:2]) + "." + "".join(list(result)[2:5])) self.ls.append(y)
def gfxinfo(self): # 获取绘制帧的时间数组 times = utils.shell( "dumpsys gfxinfo com.example.app grep View hierarchy").stdout.readlines() # 计算帧数量 frame_count = len(times) # 计算绘制每一帧的总时间,单位:ms count_time = [] for gfx in times: time = gfx.split() sum_time = float(time[0]) + float(time[1]) + float(time[2]) + float(time[3]) count_time.append(sum_time) return frame_count, count_time
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.decode('UTF-8').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) print("电池温度", self.ls)
def run(self): mem_command = '"dumpsys meminfo %s |grep TOTAL"' % self.pkg # print mem_command while True: if utils.stop != True: break sleep(1) y = [] tm = utils.timestamp() results = (utils.shell(mem_command).stdout.readline() ).decode('UTF-8').split()[1:8] print("内存:%s" % results) y.append(tm) for index in results: y.append(index) self.ls.append(y) print(self.ls)
def get_total_cpu_time(): user = nice = system = idle = iowait = irq = softirq = 0 ''' user:从系统启动开始累计到当前时刻,处于用户态的运行时间,不包含 nice值为负进程。 nice:从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间 system 从系统启动开始累计到当前时刻,处于核心态的运行时间 idle 从系统启动开始累计到当前时刻,除IO等待时间以外的其它等待时间 iowait 从系统启动开始累计到当前时刻,IO等待时间(since 2.5.41) irq 从系统启动开始累计到当前时刻,硬中断时间(since 2.6.0-test4) softirq 从系统启动开始累计到当前时刻,软中断时间(since 2.6.0-test4) stealstolen 这是时间花在其他的操作系统在虚拟环境中运行时(since 2.6.11) guest 这是运行时间guest 用户Linux内核的操作系统的控制下的一个虚拟CPU(since 2.6.24) ''' command = "cat /proc/stat" time = utils.shell(command).stdout.readline().split() total_time = 0 # for i in time: # total_time += int(i) # return total_time for info in time: if info.decode() == "cpu": user = time[1].decode() nice = time[2].decode() system = time[3].decode() idle = time[4].decode() iowait = time[5].decode() irq = time[6].decode() softirq = time[7].decode() print("user="******"nice=" + nice) print("system=" + system) print("idle=" + idle) print("iowait=" + iowait) print("irq=" + irq) print("softirq=" + softirq) total_time = int(user) + int(nice) + int(system) + int( idle) + int(iowait) + int(irq) + int(softirq) print("totalCpuTime:" + str(total_time)) return total_time
# -*- coding: utf-8 -*- from time import sleep from bin.scriptUtils import utils app_time = [] system_time = [] app_start_time = utils.shell("am start -W -n com.longtu.weifuhua/com.longtu.weifuhua.ui.homepage.activity.ServiceActivity").stdout.readlines()[4:6] result = [] for i in app_start_time: result.append(i.split()[1]) app_time.append(result[0]) system_time.append(result[1]) print ("APP自身启动耗时:", app_time) print ("系统启动APP耗时:", system_time) utils.kill_application("com.longtu.weifuhua")
def uid(): uid = utils.shell("ps | grep " + pkg + "| gawk '{ print $2 }'").stdout.readline().strip("\n") return uid
def total_mem(): total_mem = utils.shell( "cat /proc/meminfo|grep MemTotal").stdout.readlines() return total_mem
def pid(): pid = utils.shell("dumpsys package " + pkg + "|grep packageSetting|cut -d \"/\" -f2|cut -d \"}\" -f1" ).stdout.readline().strip("\n") return pid
def get_DisplayDeviceInfo(self): result = utils.shell("dumpsys display | findstr DisplayDeviceInfo" ).stdout.readline().split(",")[1].strip() print("分辨率:", result) print(result)
def get_memInfo(self): result = utils.shell('cat /proc/meminfo|findstr "MemTotal"' ).stdout.readline().split(":")[1].strip() MemTotal = "{val}MB".format(val=int(result.split()[0]) / 1024) print("总内存:%s" % MemTotal) return result