-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestWin.py
144 lines (128 loc) · 4.33 KB
/
TestWin.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
from PyQt5.QtCore import pyqtSlot, QFileInfo, QUrl
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebChannel import QWebChannel
# from AppMonkey import *
import os
import time
import subprocess
class GetStat:
def __init__(self):
self.cpu = 0
self.acpu = 0
self.amem = 0
self.mem = 0
self.vss = 0
self.rss = 0
def run(self, app):
# p = os.popen('adb shell top -m 1 -n 1 -t | grep System')
if app.strip():
cmd = 'adb shell top -n 1 | grep -e System -e ' + app
else:
cmd = 'adb shell top -n 1 | grep -e System'
p = os.popen(cmd)
a = p.readline()
b = a.split(',')
user = b[0].strip().split(' ')[1].replace('%', '')
system = b[1].strip().split(' ')[1].replace('%', '')
try:
self.cpu = float(user) + float(system)
# print('cpu:'+str(self.cpu))
except Exception as e:
pass
if app.strip():
try:
a1 = p.readline().strip()
b1 = a1.split()[4]
self.acpu = float(b1.strip().replace('%', ''))
self.vss = float(int(a1.split()[7].strip().replace('K', ''))/1024)
self.rss = float(int(a1.split()[8].strip().replace('K', ''))/1024)
except Exception as e:
pass
# print('acpu:'+str(self.acpu))
# p2 = os.popen('adb shell dumpsys meminfo|grep -e calculator -e "Total RAM"')
# a2 = p2.readline().strip().split()
# try:
# self.amem = a2[0].replace(',', '').replace('K:', '')
# p2.readline()
# b2 = p2.readline().strip().split()[2].replace(',', '').replace('K', '')
# self.mem = int(b2)
# print('amem:'+str(self.amem))
# except Exception as e:
# pass
# p1 = os.popen('adb shell dumpsys cpuinfo |grep calculator')
# a1 = p1.read().strip()
# b1 = a1.split(' ')[0]
# try:
# self.acpu = float(b1.strip().replace('%', ''))
# except Exception as e:
# pass
# print(self.acpu)
class MyShareObject(QWidget):
def __init__(self):
super().__init__()
self.value = ''
self.flag = 1
@pyqtSlot(result=str)
def QtToWeb(self):
print('456')
return 'back to web'
@pyqtSlot(str, result=str)
def WebToQt(self, value):
print(value)
self.value = value
return value
@pyqtSlot(str)
def Run(self, value):
# self.flag = 1
print(value)
t0 = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
if not os.path.isdir('./report/'):
os.mkdir('./report/')
sel = 'adb shell monkey '+value+' 1>./report/' + t0 + '_info.txt 2>./report/' + t0 + '_error.txt '
print(sel)
self.p = subprocess.Popen(sel, shell=True)
# while self.flag:
# if p.poll() == 0:
# self.flag = 0
@pyqtSlot(str, result=list)
def Cpu(self, app):
# print('CPU')
# thd = MyThread()
# ti = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# print(ti)
# t = ti.split(' ')[1]
# thd.start()
# thd.join()
# c = thd.get_cpu()
# print([t, str(c)])
# # return [t, str(c)]
# return str(c)
g = GetStat()
g.run(app)
return [str(g.cpu), str(g.acpu), str(g.vss), str(g.rss)]
class MainWindow(QMainWindow):
def __init__(self):
self.value = ''
super(QMainWindow, self).__init__()
self.setWindowTitle("APP Monkey")
# 相当于初始化这个加载web的控件
self.view = QWebEngineView(self)
# 加载外部页面,调用
url = QFileInfo('.\\Monkey.html').absoluteFilePath()
print(url)
# self.view.load(QUrl('file:///'+url))
self.view.load(QUrl(url))
self.setCentralWidget(self.view)
self.resize(1000, 600)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MainWindow()
channel = QWebChannel()
share = MyShareObject()
# share.con.connect()
channel.registerObject('share', share)
win.view.page().setWebChannel(channel)
win.show()
sys.exit(app.exec_())