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
| def get_cpu(pkg_name): cmd = "adb shell dumpsys cpuinfo | findstr " + pkg_name print(cmd) output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() for info in output: if info.split()[1].decode().split("/")[1][:-1] == pkg_name: # 只有包名相等 # print("cpu=" + info.split()[2].decode()) cpu.append(float(info.split()[2].decode().split("%")[0])) print("----cpu-----") print(cpu) return cpu
def get_men(pkg_name): cmd = "adb shell dumpsys meminfo %s" % (pkg_name) print(cmd) men_s = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() for info in men_s: if len(info.split()) and info.split()[0].decode() == "TOTAL": # print("men="+info.split()[1].decode()) men.append(int(info.split()[1].decode())) print("----men----") print(men) return men
# 得到fps ''' @author fenfenzhong '''
def get_fps(pkg_name): _adb = "adb shell dumpsys gfxinfo %s" % pkg_name print(_adb) results = os.popen(_adb).read().strip() frames = [x for x in results.split('\n') if validator(x)] frame_count = len(frames) jank_count = 0 vsync_overtime = 0 render_time = 0 for frame in frames: time_block = re.split(r'\s+', frame.strip()) if len(time_block) == 3: try: render_time = float(time_block[0]) + float(time_block[1]) + float(time_block[2]) except Exception as e: render_time = 0
if render_time > 16.67: jank_count += 1 if render_time % 16.67 == 0: vsync_overtime += int(render_time / 16.67) - 1 else: vsync_overtime += int(render_time / 16.67)
_fps = int(frame_count * 60 / (frame_count + vsync_overtime)) fps.append(_fps) # return (frame_count, jank_count, fps) print("-----fps------") print(fps) return fps
def get_battery(): _batter = subprocess.Popen("adb shell dumpsys battery", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() for info in _batter: if info.split()[0].decode() == "level:": battery.append(int(info.split()[1].decode())) print("-----battery------") print(battery) return int(info.split()[1].decode())
def get_pid(pkg_name): pid = subprocess.Popen("adb shell ps | findstr " + pkg_name, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() for item in pid: if item.split()[8].decode() == pkg_name: return item.split()[1].decode()
def get_flow(pkg_name, type): pid = get_pid(pkg_name) if pid is not None: _flow = subprocess.Popen("adb shell cat /proc/" + pid + "/net/dev", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() for item in _flow: if type == "wifi" and item.split()[0].decode() == "wlan0:": # wifi # 0 上传流量,1 下载流量 flow[0].append(int(item.split()[1].decode())) flow[1].append(int(item.split()[9].decode())) print("------flow---------") print(flow) return flow if type == "gprs" and item.split()[0].decode() == "rmnet0:": # gprs print("--------------") flow[0].append(int(item.split()[1].decode())) flow[1].append(int(item.split()[9].decode())) return flow else: flow[0].append(0) flow[1].append(0) return flow
|