├── AATT.py ├── MatplotlibWidget.py ├── README.md ├── __pycache__ ├── aatt_pyqt.cpython-34.pyc └── adb_common.cpython-34.pyc ├── aatt_pyqt.py ├── aatt_pyqt.ui ├── adb_common.py ├── call.py └── jiemian102.png /AATT.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | #author='Shichao-Dong' 3 | 4 | import sys 5 | import random,time 6 | import matplotlib 7 | import re,subprocess,os 8 | 9 | matplotlib.use("Qt5Agg") 10 | from PyQt5.QtCore import * 11 | from PyQt5.QtGui import * 12 | from PyQt5.QtWidgets import * 13 | import matplotlib.pyplot as plt 14 | from aatt_pyqt import Ui_Form 15 | import adb_common as adb 16 | 17 | class Main(QMainWindow,Ui_Form): 18 | 19 | def __init__(self,parent=None): 20 | super(Main,self).__init__(parent) 21 | self.ui = Ui_Form() 22 | self.ui.setupUi(self) 23 | self.setWindowTitle('Waiqin365-AATT-V1.1.0') 24 | 25 | self.ui.checkdev.clicked.connect(self.setdevices) 26 | self.ui.getpackage.clicked.connect(self.setpackage) 27 | self.ui.cleartext.clicked.connect(self.clearall) 28 | 29 | self.ui.comboBox.activated.connect(self.wait_time) 30 | 31 | #初始化一个定时器 32 | self.timer = QTimer(self) 33 | self.timer.timeout.connect(self.slotadd) 34 | self.ui.start.clicked.connect(self.startTimer) 35 | self.ui.end.clicked.connect(self.endTimer) 36 | 37 | self.ui.mem_plot.setVisible(False) 38 | 39 | @pyqtSlot() 40 | def on_pushButton_clicked(self): 41 | self.ui.mem_plot.setVisible(True) 42 | self.ui.mem_plot.mpl.start_static_plot() 43 | 44 | 45 | def setdevices(self): 46 | ''' 47 | 写入设备名 48 | :return: 49 | ''' 50 | self.ui.dev.setText(adb.get_devices()) 51 | 52 | def setpackage(self): 53 | ''' 54 | 写入package 和 activity 55 | :return: 56 | ''' 57 | self.ui.packagename.setText(adb.getpackagename()) 58 | self.ui.activity.setText(adb.getactivity()) 59 | 60 | def wait_time(self): 61 | ''' 62 | 设置更新时间 63 | :return: 64 | ''' 65 | timetext = self.ui.comboBox.currentText() 66 | wait_time = int(timetext) * 1000 67 | print(wait_time) 68 | return wait_time 69 | 70 | def slotadd(self): 71 | ''' 72 | 往mem、cpu、flow写数据 73 | :return: 74 | ''' 75 | memlist = adb.mem() 76 | mem = 'mem占用:'+ str(memlist[-1]) 77 | cpulist = adb.cpu() 78 | cpu = 'cpu占用:'+ str(cpulist[-1]) 79 | self.ui.mem.append(mem) 80 | self.ui.cpu.append(cpu) 81 | (recevice,send,allflow)=adb.getflow() 82 | receflow = '下载流量:' + str(int(recevice[-1])) 83 | sendflow = '上传流量:' + str(int(send[-1])) 84 | alladd = '总流量:' + str(int(allflow[-1])) 85 | self.ui.recv.append(receflow) 86 | self.ui.send.append(sendflow) 87 | self.ui.all.append(alladd) 88 | 89 | def startTimer(self): 90 | ''' 91 | 设置时间间隔并启动定时器 92 | :return: 93 | ''' 94 | print(self.ui.comboBox.currentText()) 95 | self.timer.start(self.wait_time()) 96 | self.ui.start.setEnabled(False) 97 | self.ui.end.setEnabled(True) 98 | 99 | def endTimer(self): 100 | self.timer.stop() 101 | self.ui.start.setEnabled(True) 102 | 103 | def clearall(self): 104 | ''' 105 | 清屏 106 | :return: 107 | ''' 108 | self.ui.mem.clear() 109 | self.ui.cpu.clear() 110 | self.ui.recv.clear() 111 | self.ui.send.clear() 112 | self.ui.all.clear() 113 | 114 | if __name__ == "__main__": 115 | import sys 116 | 117 | app = QApplication(sys.argv) 118 | ui = Main() 119 | ui.show() 120 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /MatplotlibWidget.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | #author='Shichao-Dong' 3 | 4 | import sys 5 | import random 6 | import matplotlib 7 | 8 | matplotlib.use("Qt5Agg") 9 | from PyQt5 import QtCore 10 | from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QSizePolicy, QWidget 11 | from numpy import arange, sin, pi 12 | from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas 13 | from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar 14 | from matplotlib.figure import Figure 15 | import matplotlib.pyplot as plt 16 | import adb_common as adb 17 | 18 | 19 | class MyMplCanvas(FigureCanvas): 20 | """FigureCanvas的最终的父类其实是QWidget。""" 21 | 22 | def __init__(self, parent=None, width=5, height=4, dpi=100): 23 | 24 | # 配置中文显示 25 | plt.rcParams['font.family'] = ['SimHei'] # 用来正常显示中文标签 26 | plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 27 | 28 | self.fig = plt.figure(figsize=(width, height), dpi=dpi) # 新建一个figure 29 | 30 | self.axes = self.fig.add_subplot(311) # 建立一个子图,如果要建立复合图,可以在这里修改 31 | self.axes1 = self.fig.add_subplot(312) 32 | self.axes2 = self.fig.add_subplot(313) 33 | 34 | self.axes.hold(False) # 每次绘图的时候不保留上一次绘图的结果 35 | # self.axes1.hold(False) 36 | 37 | FigureCanvas.__init__(self, self.fig) 38 | self.setParent(parent) 39 | 40 | '''定义FigureCanvas的尺寸策略,这部分的意思是设置FigureCanvas,使之尽可能的向外填充空间。''' 41 | FigureCanvas.setSizePolicy(self, 42 | QSizePolicy.Expanding, 43 | QSizePolicy.Expanding) 44 | FigureCanvas.updateGeometry(self) 45 | 46 | '''绘制静态图,可以在这里定义自己的绘图逻辑''' 47 | 48 | def start_static_plot(self): 49 | 50 | self.fig.suptitle('性能监测图') 51 | 52 | self.axes.plot(adb.mem()) 53 | self.axes.set_ylabel('mem占用:k') 54 | self.axes.grid(True) 55 | 56 | self.axes1.plot(adb.cpu(),'y') 57 | self.axes1.set_ylabel('cpu占用:%') 58 | self.axes1.grid(True) 59 | 60 | flow = adb.getflow() 61 | self.axes2.plot(flow[0],'b',flow[1],'r') 62 | self.axes2.set_ylabel('流量使用:k') 63 | self.axes2.set_xlabel('蓝色下载,红色上传') 64 | self.axes2.grid(True) 65 | 66 | '''启动绘制动态图''' 67 | 68 | def start_dynamic_plot(self, *args, **kwargs): 69 | timer = QtCore.QTimer(self) 70 | timer.timeout.connect(self.update_figure) # 每隔一段时间就会触发一次update_figure函数。 71 | timer.start(1000) # 触发的时间间隔为1秒。 72 | 73 | '''动态图的绘图逻辑可以在这里修改''' 74 | 75 | def update_figure(self): 76 | self.fig.suptitle('测试动态图') 77 | l = [random.randint(0, 10) for i in range(4)] 78 | self.axes.plot([0, 1, 2, 3], l, 'r') 79 | self.axes.set_ylabel('动态图:Y轴') 80 | self.axes.set_xlabel('动态图:X轴') 81 | self.axes.grid(True) 82 | self.draw() 83 | 84 | 85 | class MatplotlibWidget(QWidget): 86 | def __init__(self, parent=None): 87 | super(MatplotlibWidget, self).__init__(parent) 88 | self.initUi() 89 | 90 | def initUi(self): 91 | self.layout = QVBoxLayout(self) 92 | self.mpl = MyMplCanvas(self, width=5, height=4, dpi=100) 93 | #self.mpl.start_static_plot() # 如果你想要初始化的时候就呈现静态图,请把这行注释去掉 94 | #self.mpl.start_dynamic_plot() # 如果你想要初始化的时候就呈现动态图,请把这行注释去掉 95 | self.mpl_ntb = NavigationToolbar(self.mpl, self) # 添加完整的 toolbar 96 | 97 | self.layout.addWidget(self.mpl) 98 | # self.layout.addWidget(self.mpl_ntb) 99 | 100 | 101 | if __name__ == '__main__': 102 | app = QApplication(sys.argv) 103 | ui = MatplotlibWidget() 104 | ui.mpl.start_static_plot() # 测试静态图效果 105 | # ui.mpl.start_dynamic_plot() # 测试动态图效果 106 | ui.show() 107 | sys.exit(app.exec_()) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AATT 2 | ## 一款安卓性能测试工具 3 | #### 环境说明 4 | 1.windows + python3 + PyQt5 5 | 性能数据采集主要基于常用的adb 命令 6 | 7 | #### 主界面: 8 | 9 | ![image](https://github.com/NJ-zero/AATT/raw/master/jiemian102.png) 10 | 11 | ##### V1.0.0版本说明 12 | 点击检查设备---显示设备SN 13 | 14 | 打开待测应用,获取packagename 和 activity 15 | 16 | 根据刷新时间定时刷新 17 | 18 | 点击开始,开始测试,结束,结束测试 19 | 20 | 后期可优化点: 21 | 22 | 1.增加弹窗提示 23 | 24 | 2.增加表格显示 25 | 26 | 3.设备断开自动停止测试 27 | 28 | ##### V1.0.2优化 29 | 增加关闭和清屏功能 30 | 31 | 点击关闭,关闭窗口;点击清除,清除写入的mem/cpu/flow等信息 32 | 33 | ##### V1.1.0 优化 34 | 35 | 增加图表显示,测试结束后,点击图表生成三张图 -------------------------------------------------------------------------------- /__pycache__/aatt_pyqt.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NJ-zero/AATT/caf2a5c193dd9ef83edaf3036ee89c64566f080c/__pycache__/aatt_pyqt.cpython-34.pyc -------------------------------------------------------------------------------- /__pycache__/adb_common.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NJ-zero/AATT/caf2a5c193dd9ef83edaf3036ee89c64566f080c/__pycache__/adb_common.cpython-34.pyc -------------------------------------------------------------------------------- /aatt_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'aatt_pyqt.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.4.1 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | 11 | class Ui_Form(object): 12 | def setupUi(self, Form): 13 | Form.setObjectName("Form") 14 | Form.resize(1114, 701) 15 | self.all = QtWidgets.QTextEdit(Form) 16 | self.all.setGeometry(QtCore.QRect(957, 97, 147, 192)) 17 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 18 | sizePolicy.setHorizontalStretch(0) 19 | sizePolicy.setVerticalStretch(0) 20 | sizePolicy.setHeightForWidth(self.all.sizePolicy().hasHeightForWidth()) 21 | self.all.setSizePolicy(sizePolicy) 22 | self.all.setObjectName("all") 23 | self.recv = QtWidgets.QTextEdit(Form) 24 | self.recv.setGeometry(QtCore.QRect(520, 97, 146, 192)) 25 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 26 | sizePolicy.setHorizontalStretch(0) 27 | sizePolicy.setVerticalStretch(0) 28 | sizePolicy.setHeightForWidth(self.recv.sizePolicy().hasHeightForWidth()) 29 | self.recv.setSizePolicy(sizePolicy) 30 | self.recv.setObjectName("recv") 31 | self.label_9 = QtWidgets.QLabel(Form) 32 | self.label_9.setGeometry(QtCore.QRect(672, 97, 66, 16)) 33 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 34 | sizePolicy.setHorizontalStretch(0) 35 | sizePolicy.setVerticalStretch(0) 36 | sizePolicy.setHeightForWidth(self.label_9.sizePolicy().hasHeightForWidth()) 37 | self.label_9.setSizePolicy(sizePolicy) 38 | self.label_9.setObjectName("label_9") 39 | self.send = QtWidgets.QTextEdit(Form) 40 | self.send.setGeometry(QtCore.QRect(744, 97, 147, 192)) 41 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 42 | sizePolicy.setHorizontalStretch(0) 43 | sizePolicy.setVerticalStretch(0) 44 | sizePolicy.setHeightForWidth(self.send.sizePolicy().hasHeightForWidth()) 45 | self.send.setSizePolicy(sizePolicy) 46 | self.send.setObjectName("send") 47 | self.label_10 = QtWidgets.QLabel(Form) 48 | self.label_10.setGeometry(QtCore.QRect(897, 97, 54, 16)) 49 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 50 | sizePolicy.setHorizontalStretch(0) 51 | sizePolicy.setVerticalStretch(0) 52 | sizePolicy.setHeightForWidth(self.label_10.sizePolicy().hasHeightForWidth()) 53 | self.label_10.setSizePolicy(sizePolicy) 54 | self.label_10.setObjectName("label_10") 55 | self.label_6 = QtWidgets.QLabel(Form) 56 | self.label_6.setGeometry(QtCore.QRect(10, 97, 60, 16)) 57 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 58 | sizePolicy.setHorizontalStretch(0) 59 | sizePolicy.setVerticalStretch(0) 60 | sizePolicy.setHeightForWidth(self.label_6.sizePolicy().hasHeightForWidth()) 61 | self.label_6.setSizePolicy(sizePolicy) 62 | self.label_6.setObjectName("label_6") 63 | self.mem = QtWidgets.QTextEdit(Form) 64 | self.mem.setGeometry(QtCore.QRect(76, 97, 147, 192)) 65 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 66 | sizePolicy.setHorizontalStretch(0) 67 | sizePolicy.setVerticalStretch(0) 68 | sizePolicy.setHeightForWidth(self.mem.sizePolicy().hasHeightForWidth()) 69 | self.mem.setSizePolicy(sizePolicy) 70 | self.mem.setObjectName("mem") 71 | self.label_7 = QtWidgets.QLabel(Form) 72 | self.label_7.setGeometry(QtCore.QRect(229, 97, 60, 16)) 73 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 74 | sizePolicy.setHorizontalStretch(0) 75 | sizePolicy.setVerticalStretch(0) 76 | sizePolicy.setHeightForWidth(self.label_7.sizePolicy().hasHeightForWidth()) 77 | self.label_7.setSizePolicy(sizePolicy) 78 | self.label_7.setObjectName("label_7") 79 | self.cpu = QtWidgets.QTextEdit(Form) 80 | self.cpu.setGeometry(QtCore.QRect(295, 97, 147, 192)) 81 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 82 | sizePolicy.setHorizontalStretch(0) 83 | sizePolicy.setVerticalStretch(0) 84 | sizePolicy.setHeightForWidth(self.cpu.sizePolicy().hasHeightForWidth()) 85 | self.cpu.setSizePolicy(sizePolicy) 86 | self.cpu.setObjectName("cpu") 87 | self.label_8 = QtWidgets.QLabel(Form) 88 | self.label_8.setGeometry(QtCore.QRect(448, 97, 66, 16)) 89 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 90 | sizePolicy.setHorizontalStretch(0) 91 | sizePolicy.setVerticalStretch(0) 92 | sizePolicy.setHeightForWidth(self.label_8.sizePolicy().hasHeightForWidth()) 93 | self.label_8.setSizePolicy(sizePolicy) 94 | self.label_8.setObjectName("label_8") 95 | self.dev = QtWidgets.QLineEdit(Form) 96 | self.dev.setGeometry(QtCore.QRect(70, 10, 231, 20)) 97 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Minimum) 98 | sizePolicy.setHorizontalStretch(0) 99 | sizePolicy.setVerticalStretch(0) 100 | sizePolicy.setHeightForWidth(self.dev.sizePolicy().hasHeightForWidth()) 101 | self.dev.setSizePolicy(sizePolicy) 102 | self.dev.setObjectName("dev") 103 | self.checkdev = QtWidgets.QPushButton(Form) 104 | self.checkdev.setGeometry(QtCore.QRect(320, 10, 75, 23)) 105 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) 106 | sizePolicy.setHorizontalStretch(0) 107 | sizePolicy.setVerticalStretch(0) 108 | sizePolicy.setHeightForWidth(self.checkdev.sizePolicy().hasHeightForWidth()) 109 | self.checkdev.setSizePolicy(sizePolicy) 110 | self.checkdev.setObjectName("checkdev") 111 | self.label_2 = QtWidgets.QLabel(Form) 112 | self.label_2.setGeometry(QtCore.QRect(410, 10, 42, 16)) 113 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) 114 | sizePolicy.setHorizontalStretch(0) 115 | sizePolicy.setVerticalStretch(0) 116 | sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth()) 117 | self.label_2.setSizePolicy(sizePolicy) 118 | self.label_2.setObjectName("label_2") 119 | self.label = QtWidgets.QLabel(Form) 120 | self.label.setGeometry(QtCore.QRect(10, 10, 36, 16)) 121 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Minimum) 122 | sizePolicy.setHorizontalStretch(0) 123 | sizePolicy.setVerticalStretch(0) 124 | sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) 125 | self.label.setSizePolicy(sizePolicy) 126 | self.label.setObjectName("label") 127 | self.apppath = QtWidgets.QLineEdit(Form) 128 | self.apppath.setGeometry(QtCore.QRect(480, 10, 281, 20)) 129 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) 130 | sizePolicy.setHorizontalStretch(0) 131 | sizePolicy.setVerticalStretch(0) 132 | sizePolicy.setHeightForWidth(self.apppath.sizePolicy().hasHeightForWidth()) 133 | self.apppath.setSizePolicy(sizePolicy) 134 | self.apppath.setObjectName("apppath") 135 | self.label_3 = QtWidgets.QLabel(Form) 136 | self.label_3.setGeometry(QtCore.QRect(810, 10, 48, 16)) 137 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) 138 | sizePolicy.setHorizontalStretch(0) 139 | sizePolicy.setVerticalStretch(0) 140 | sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth()) 141 | self.label_3.setSizePolicy(sizePolicy) 142 | self.label_3.setObjectName("label_3") 143 | self.comboBox = QtWidgets.QComboBox(Form) 144 | self.comboBox.setGeometry(QtCore.QRect(900, 10, 71, 20)) 145 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) 146 | sizePolicy.setHorizontalStretch(0) 147 | sizePolicy.setVerticalStretch(0) 148 | sizePolicy.setHeightForWidth(self.comboBox.sizePolicy().hasHeightForWidth()) 149 | self.comboBox.setSizePolicy(sizePolicy) 150 | self.comboBox.setObjectName("comboBox") 151 | self.comboBox.addItem("") 152 | self.comboBox.addItem("") 153 | self.comboBox.addItem("") 154 | self.comboBox.addItem("") 155 | self.comboBox.addItem("") 156 | self.comboBox.addItem("") 157 | self.comboBox.addItem("") 158 | self.packagename = QtWidgets.QLineEdit(Form) 159 | self.packagename.setGeometry(QtCore.QRect(70, 50, 231, 20)) 160 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) 161 | sizePolicy.setHorizontalStretch(0) 162 | sizePolicy.setVerticalStretch(0) 163 | sizePolicy.setHeightForWidth(self.packagename.sizePolicy().hasHeightForWidth()) 164 | self.packagename.setSizePolicy(sizePolicy) 165 | self.packagename.setObjectName("packagename") 166 | self.label_4 = QtWidgets.QLabel(Form) 167 | self.label_4.setGeometry(QtCore.QRect(10, 54, 48, 16)) 168 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 169 | sizePolicy.setHorizontalStretch(0) 170 | sizePolicy.setVerticalStretch(0) 171 | sizePolicy.setHeightForWidth(self.label_4.sizePolicy().hasHeightForWidth()) 172 | self.label_4.setSizePolicy(sizePolicy) 173 | self.label_4.setObjectName("label_4") 174 | self.getpackage = QtWidgets.QPushButton(Form) 175 | self.getpackage.setGeometry(QtCore.QRect(321, 54, 75, 23)) 176 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 177 | sizePolicy.setHorizontalStretch(0) 178 | sizePolicy.setVerticalStretch(0) 179 | sizePolicy.setHeightForWidth(self.getpackage.sizePolicy().hasHeightForWidth()) 180 | self.getpackage.setSizePolicy(sizePolicy) 181 | self.getpackage.setObjectName("getpackage") 182 | self.label_5 = QtWidgets.QLabel(Form) 183 | self.label_5.setGeometry(QtCore.QRect(402, 54, 72, 16)) 184 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 185 | sizePolicy.setHorizontalStretch(0) 186 | sizePolicy.setVerticalStretch(0) 187 | sizePolicy.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth()) 188 | self.label_5.setSizePolicy(sizePolicy) 189 | self.label_5.setObjectName("label_5") 190 | self.activity = QtWidgets.QLineEdit(Form) 191 | self.activity.setGeometry(QtCore.QRect(480, 54, 281, 20)) 192 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) 193 | sizePolicy.setHorizontalStretch(0) 194 | sizePolicy.setVerticalStretch(0) 195 | sizePolicy.setHeightForWidth(self.activity.sizePolicy().hasHeightForWidth()) 196 | self.activity.setSizePolicy(sizePolicy) 197 | self.activity.setObjectName("activity") 198 | self.start = QtWidgets.QPushButton(Form) 199 | self.start.setGeometry(QtCore.QRect(809, 54, 75, 23)) 200 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 201 | sizePolicy.setHorizontalStretch(0) 202 | sizePolicy.setVerticalStretch(0) 203 | sizePolicy.setHeightForWidth(self.start.sizePolicy().hasHeightForWidth()) 204 | self.start.setSizePolicy(sizePolicy) 205 | self.start.setObjectName("start") 206 | self.end = QtWidgets.QPushButton(Form) 207 | self.end.setGeometry(QtCore.QRect(900, 54, 75, 23)) 208 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 209 | sizePolicy.setHorizontalStretch(0) 210 | sizePolicy.setVerticalStretch(0) 211 | sizePolicy.setHeightForWidth(self.end.sizePolicy().hasHeightForWidth()) 212 | self.end.setSizePolicy(sizePolicy) 213 | self.end.setObjectName("end") 214 | self.close = QtWidgets.QPushButton(Form) 215 | self.close.setGeometry(QtCore.QRect(1010, 10, 75, 23)) 216 | self.close.setObjectName("close") 217 | self.cleartext = QtWidgets.QPushButton(Form) 218 | self.cleartext.setGeometry(QtCore.QRect(1010, 54, 75, 23)) 219 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 220 | sizePolicy.setHorizontalStretch(0) 221 | sizePolicy.setVerticalStretch(0) 222 | sizePolicy.setHeightForWidth(self.cleartext.sizePolicy().hasHeightForWidth()) 223 | self.cleartext.setSizePolicy(sizePolicy) 224 | self.cleartext.setObjectName("cleartext") 225 | self.mem_plot = MatplotlibWidget(Form) 226 | self.mem_plot.setGeometry(QtCore.QRect(70, 300, 1021, 381)) 227 | self.mem_plot.setObjectName("mem_plot") 228 | self.pushButton = QtWidgets.QPushButton(Form) 229 | self.pushButton.setGeometry(QtCore.QRect(0, 410, 61, 23)) 230 | sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) 231 | sizePolicy.setHorizontalStretch(0) 232 | sizePolicy.setVerticalStretch(0) 233 | sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth()) 234 | self.pushButton.setSizePolicy(sizePolicy) 235 | self.pushButton.setObjectName("pushButton") 236 | 237 | self.retranslateUi(Form) 238 | self.close.clicked.connect(Form.close) 239 | QtCore.QMetaObject.connectSlotsByName(Form) 240 | 241 | def retranslateUi(self, Form): 242 | _translate = QtCore.QCoreApplication.translate 243 | Form.setWindowTitle(_translate("Form", "Form")) 244 | self.label_9.setText(_translate("Form", "上传流量(k)")) 245 | self.label_10.setText(_translate("Form", "总流量(k)")) 246 | self.label_6.setText(_translate("Form", "mem占用(M)")) 247 | self.label_7.setText(_translate("Form", "cpu占用(%)")) 248 | self.label_8.setText(_translate("Form", "下载流量(k)")) 249 | self.checkdev.setText(_translate("Form", "检查设备")) 250 | self.label_2.setText(_translate("Form", "app路径")) 251 | self.label.setText(_translate("Form", "设备号")) 252 | self.label_3.setText(_translate("Form", "更新时间")) 253 | self.comboBox.setItemText(0, _translate("Form", "选择时间")) 254 | self.comboBox.setItemText(1, _translate("Form", "1")) 255 | self.comboBox.setItemText(2, _translate("Form", "2")) 256 | self.comboBox.setItemText(3, _translate("Form", "5")) 257 | self.comboBox.setItemText(4, _translate("Form", "10")) 258 | self.comboBox.setItemText(5, _translate("Form", "20")) 259 | self.comboBox.setItemText(6, _translate("Form", "30")) 260 | self.label_4.setText(_translate("Form", "应用包名")) 261 | self.getpackage.setText(_translate("Form", "获取")) 262 | self.label_5.setText(_translate("Form", "应用activity")) 263 | self.start.setText(_translate("Form", "开始")) 264 | self.end.setText(_translate("Form", "结束")) 265 | self.close.setText(_translate("Form", "关闭")) 266 | self.cleartext.setText(_translate("Form", "清除")) 267 | self.pushButton.setText(_translate("Form", "图表")) 268 | 269 | from MatplotlibWidget import MatplotlibWidget 270 | -------------------------------------------------------------------------------- /aatt_pyqt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1114 10 | 701 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 957 20 | 97 21 | 147 22 | 192 23 | 24 | 25 | 26 | 27 | 0 28 | 0 29 | 30 | 31 | 32 | 33 | 34 | 35 | 520 36 | 97 37 | 146 38 | 192 39 | 40 | 41 | 42 | 43 | 0 44 | 0 45 | 46 | 47 | 48 | 49 | 50 | 51 | 672 52 | 97 53 | 66 54 | 16 55 | 56 | 57 | 58 | 59 | 0 60 | 0 61 | 62 | 63 | 64 | 上传流量(k) 65 | 66 | 67 | 68 | 69 | 70 | 744 71 | 97 72 | 147 73 | 192 74 | 75 | 76 | 77 | 78 | 0 79 | 0 80 | 81 | 82 | 83 | 84 | 85 | 86 | 897 87 | 97 88 | 54 89 | 16 90 | 91 | 92 | 93 | 94 | 0 95 | 0 96 | 97 | 98 | 99 | 总流量(k) 100 | 101 | 102 | 103 | 104 | 105 | 10 106 | 97 107 | 60 108 | 16 109 | 110 | 111 | 112 | 113 | 0 114 | 0 115 | 116 | 117 | 118 | mem占用(M) 119 | 120 | 121 | 122 | 123 | 124 | 76 125 | 97 126 | 147 127 | 192 128 | 129 | 130 | 131 | 132 | 0 133 | 0 134 | 135 | 136 | 137 | 138 | 139 | 140 | 229 141 | 97 142 | 60 143 | 16 144 | 145 | 146 | 147 | 148 | 0 149 | 0 150 | 151 | 152 | 153 | cpu占用(%) 154 | 155 | 156 | 157 | 158 | 159 | 295 160 | 97 161 | 147 162 | 192 163 | 164 | 165 | 166 | 167 | 0 168 | 0 169 | 170 | 171 | 172 | 173 | 174 | 175 | 448 176 | 97 177 | 66 178 | 16 179 | 180 | 181 | 182 | 183 | 0 184 | 0 185 | 186 | 187 | 188 | 下载流量(k) 189 | 190 | 191 | 192 | 193 | 194 | 70 195 | 10 196 | 231 197 | 20 198 | 199 | 200 | 201 | 202 | 0 203 | 0 204 | 205 | 206 | 207 | 208 | 209 | 210 | 320 211 | 10 212 | 75 213 | 23 214 | 215 | 216 | 217 | 218 | 0 219 | 0 220 | 221 | 222 | 223 | 检查设备 224 | 225 | 226 | 227 | 228 | 229 | 410 230 | 10 231 | 42 232 | 16 233 | 234 | 235 | 236 | 237 | 0 238 | 0 239 | 240 | 241 | 242 | app路径 243 | 244 | 245 | 246 | 247 | 248 | 10 249 | 10 250 | 36 251 | 16 252 | 253 | 254 | 255 | 256 | 0 257 | 0 258 | 259 | 260 | 261 | 设备号 262 | 263 | 264 | 265 | 266 | 267 | 480 268 | 10 269 | 281 270 | 20 271 | 272 | 273 | 274 | 275 | 0 276 | 0 277 | 278 | 279 | 280 | 281 | 282 | 283 | 810 284 | 10 285 | 48 286 | 16 287 | 288 | 289 | 290 | 291 | 0 292 | 0 293 | 294 | 295 | 296 | 更新时间 297 | 298 | 299 | 300 | 301 | 302 | 900 303 | 10 304 | 71 305 | 20 306 | 307 | 308 | 309 | 310 | 0 311 | 0 312 | 313 | 314 | 315 | 316 | 选择时间 317 | 318 | 319 | 320 | 321 | 1 322 | 323 | 324 | 325 | 326 | 2 327 | 328 | 329 | 330 | 331 | 5 332 | 333 | 334 | 335 | 336 | 10 337 | 338 | 339 | 340 | 341 | 20 342 | 343 | 344 | 345 | 346 | 30 347 | 348 | 349 | 350 | 351 | 352 | 353 | 70 354 | 50 355 | 231 356 | 20 357 | 358 | 359 | 360 | 361 | 0 362 | 0 363 | 364 | 365 | 366 | 367 | 368 | 369 | 10 370 | 54 371 | 48 372 | 16 373 | 374 | 375 | 376 | 377 | 0 378 | 0 379 | 380 | 381 | 382 | 应用包名 383 | 384 | 385 | 386 | 387 | 388 | 321 389 | 54 390 | 75 391 | 23 392 | 393 | 394 | 395 | 396 | 0 397 | 0 398 | 399 | 400 | 401 | 获取 402 | 403 | 404 | 405 | 406 | 407 | 402 408 | 54 409 | 72 410 | 16 411 | 412 | 413 | 414 | 415 | 0 416 | 0 417 | 418 | 419 | 420 | 应用activity 421 | 422 | 423 | 424 | 425 | 426 | 480 427 | 54 428 | 281 429 | 20 430 | 431 | 432 | 433 | 434 | 0 435 | 0 436 | 437 | 438 | 439 | 440 | 441 | 442 | 809 443 | 54 444 | 75 445 | 23 446 | 447 | 448 | 449 | 450 | 0 451 | 0 452 | 453 | 454 | 455 | 开始 456 | 457 | 458 | 459 | 460 | 461 | 900 462 | 54 463 | 75 464 | 23 465 | 466 | 467 | 468 | 469 | 0 470 | 0 471 | 472 | 473 | 474 | 结束 475 | 476 | 477 | 478 | 479 | 480 | 1010 481 | 10 482 | 75 483 | 23 484 | 485 | 486 | 487 | 关闭 488 | 489 | 490 | 491 | 492 | 493 | 1010 494 | 54 495 | 75 496 | 23 497 | 498 | 499 | 500 | 501 | 0 502 | 0 503 | 504 | 505 | 506 | 清除 507 | 508 | 509 | 510 | 511 | 512 | 70 513 | 300 514 | 1021 515 | 381 516 | 517 | 518 | 519 | 520 | 521 | 522 | 0 523 | 410 524 | 61 525 | 23 526 | 527 | 528 | 529 | 530 | 0 531 | 0 532 | 533 | 534 | 535 | 图表 536 | 537 | 538 | 539 | 540 | 541 | MatplotlibWidget 542 | QWidget 543 |
matplotlibwidget
544 | 1 545 |
546 |
547 | 548 | 549 | 550 | close 551 | clicked() 552 | Form 553 | close() 554 | 555 | 556 | 1050 557 | 18 558 | 559 | 560 | 1107 561 | 35 562 | 563 | 564 | 565 | 566 |
567 | -------------------------------------------------------------------------------- /adb_common.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | #author='Shichao-Dong' 3 | 4 | import os,platform 5 | import subprocess 6 | import re 7 | 8 | 9 | si = subprocess.STARTUPINFO() 10 | si.dwFlags |= subprocess.STARTF_USESHOWWINDOW 11 | 12 | dev_list =[] 13 | def get_devices(): 14 | # rt = os.popen('adb devices').readlines() # os.popen()执行系统命令并返回执行后的结果 15 | # n = len(rt) - 2 16 | # print(rt) 17 | # print("当前已连接待测手机数为:" + str(n)) 18 | # if len(rt)-2 == 1: 19 | # for i in range(n): 20 | # nPos = rt[i + 1].index("\t") 21 | # dev = rt[i + 1][:nPos] 22 | # dev_list.append(dev) 23 | # print(dev_list[0]) 24 | # return dev_list[0] 25 | # else: 26 | # return 'No device found' 27 | devices = [] 28 | result = subprocess.Popen("adb devices", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 29 | # print(result[1].decode()) 30 | print(len(result)) 31 | if len(result)-2 == 1: 32 | for line in result[1:]: 33 | devices.append(line.strip().decode()) 34 | print(devices[0].split()[0]) 35 | return devices[0].split()[0] 36 | else: 37 | print('No device') 38 | return 'No device found' 39 | 40 | # return devices[0] 41 | 42 | def getpackagename(): 43 | pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+") 44 | package = subprocess.Popen("adb shell dumpsys activity | findstr mFocusedActivity", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read() 45 | package = (str(package)) 46 | packagename = pattern.findall(package)[0].split('/')[0] 47 | # print (pattern.findall(package)[0].split('/')[0]) 48 | # print (pattern.findall(package)[0].split('/')[1]) 49 | return packagename 50 | 51 | def getactivity(): 52 | pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+") 53 | package = subprocess.Popen("adb shell dumpsys activity | findstr mFocusedActivity", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read() 54 | package = (str(package)) 55 | activity = pattern.findall(package)[0].split('/')[1] 56 | return activity 57 | 58 | 59 | #获取mem占用情况 60 | mem_list = [] 61 | def mem(): 62 | cmd = 'adb -s '+ get_devices() + ' shell dumpsys meminfo ' + getpackagename() 63 | men_s = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 64 | for info in men_s: 65 | if len(info.split())>0 and info.split()[0].decode() == "TOTAL": 66 | mem_list.append((int(info.split()[1].decode())//1024)) 67 | print(str(info.split()[1].decode())) 68 | print(mem_list) 69 | # men_list = str(info.split()[1].decode()) 70 | 71 | return mem_list 72 | 73 | #获取cpu 74 | cpu_list=[] 75 | def cpu(): 76 | cmd = 'adb -s '+get_devices() + ' shell top -n 1| findstr ' + getpackagename() 77 | # print (cmd) 78 | top_info = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 79 | print (top_info) 80 | if len(top_info)>=1: 81 | cpu_list.append(int(top_info[0].split()[2][0:-1])) 82 | 83 | print (cpu_list) 84 | 85 | return cpu_list 86 | 87 | #获取pid和uid 88 | pid_list = [] 89 | def pid(): 90 | cmd = 'adb -s '+ get_devices() +' shell ps |findstr ' + getpackagename() 91 | print (cmd) 92 | pid_info = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 93 | print(int(pid_info[0].split()[1])) 94 | 95 | if len(pid_info)>=1: 96 | pid_list.append(int(pid_info[0].split()[1])) 97 | print(pid_list) 98 | return str(pid_list[0]) 99 | 100 | uid_list = [] 101 | def uid(): 102 | cmd ='adb -s '+ get_devices() +' shell cat /proc/'+ pid() + '/status' 103 | print (cmd) 104 | uid_info = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 105 | if len(uid_info)>= 1: 106 | uid_list.append(int(uid_info[6].split()[1])) 107 | print (uid_list) 108 | return str(uid_list[0]) 109 | 110 | #获取流量 111 | receive = [] 112 | sendflow = [] 113 | all = [] 114 | def flow(): 115 | cmd = 'adb -s '+ get_devices() +' shell cat /proc/net/xt_qtaguid/stats | findstr '+ uid() 116 | print (cmd) 117 | flow_info = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.readlines() 118 | down = 0 119 | up = 0 120 | if len(flow_info)>= 1: 121 | for flow in flow_info: 122 | down =down + int(flow.split()[5]) 123 | up = up+ int(flow.split()[7]) 124 | receive.append(down) 125 | sendflow.append(up) 126 | print (receive,sendflow) 127 | return (receive,sendflow) 128 | 129 | 130 | def getflow(): 131 | (receive,sendflow) = flow() 132 | recev = [] 133 | send = [] 134 | allflow = [] 135 | print(len(receive)) 136 | for i in range(len(receive)-1): 137 | recev.append((int(receive[i+1]) - int(receive[i]))//1024) 138 | send.append((int(sendflow[i+1]) - int(sendflow[i]))//1024) 139 | allflow.append(recev[i]+send[i]) 140 | print(recev,send,allflow) 141 | return recev,send,allflow 142 | 143 | 144 | 145 | 146 | if __name__ == "__main__": 147 | get_devices() 148 | getpackagename() 149 | mem() 150 | # cpu() 151 | # pid() 152 | # uid() 153 | 154 | # for i in range(20): 155 | # flow() 156 | 157 | # getflow() -------------------------------------------------------------------------------- /call.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | #author='Shichao-Dong' 3 | 4 | import sys 5 | from PyQt5.QtWidgets import * 6 | from aatt_pyqt import Ui_Form 7 | 8 | 9 | class Main(QMainWindow,Ui_Form): 10 | 11 | def __init__(self,parent=None): 12 | super(Main,self).__init__(parent) 13 | self.ui = Ui_Form() 14 | self.ui.setupUi(self) 15 | 16 | 17 | if __name__=="__main__": 18 | app = QApplication(sys.argv) 19 | win = Main() 20 | win.show() 21 | sys.exit(app.exec_()) 22 | -------------------------------------------------------------------------------- /jiemian102.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NJ-zero/AATT/caf2a5c193dd9ef83edaf3036ee89c64566f080c/jiemian102.png --------------------------------------------------------------------------------