Skip to content

Commit

Permalink
version - 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Aug 19, 2022
1 parent 463b9b5 commit 542281e
Show file tree
Hide file tree
Showing 9 changed files with 659 additions and 265 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ python3 -m solox --host=0.0.0.0 --port=50003
```
## Features
#### Home
<img src="https://cdn.nlark.com/yuque/0/2022/png/153412/1659519461516-871ecf61-4745-4c92-bf01-96fe0f7be560.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" width="100%">
<img src="https://cdn.nlark.com/yuque/0/2022/png/153412/1660883990523-03354c72-6144-4e43-a1fb-080fc1a0e299.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" width="100%">


#### Error Log
Expand All @@ -66,7 +66,7 @@ python3 -m solox --host=0.0.0.0 --port=50003
<img src="https://cdn.nlark.com/yuque/0/2022/png/153412/1648879616511-15f271b7-2761-43c5-a86c-50f82bc68f32.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" width="100%">

#### Analysis
<img src="https://user-images.githubusercontent.com/29191106/174444708-70621044-f836-446f-852f-05925e60cada.png" width="100%">
<img src="https://cdn.nlark.com/yuque/0/2022/png/153412/1660883991330-67bab00c-1001-477a-b32f-7c8aa7906481.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" width="100%">


## Thanks
Expand Down
2 changes: 1 addition & 1 deletion solox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from __future__ import absolute_import

__version__ = '2.1.0'
__version__ = '2.1.1'
247 changes: 167 additions & 80 deletions solox/public/apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

class CPU:

def __init__(self, pkgName, deviceId,platform='Android'):
def __init__(self, pkgName, deviceId, platform='Android'):
self.pkgName = pkgName
self.deviceId = deviceId
self.platform = platform
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')

def getprocessCpuStat(self):
"""Get the cpu usage of a process at a certain time"""
"""get the cpu usage of a process at a certain time"""
pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)
cmd = f'cat /proc/{pid}/stat'
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
Expand All @@ -31,59 +31,120 @@ def getprocessCpuStat(self):
return processCpu

def getTotalCpuStat(self):
"""Get the total cpu usage at a certain time"""

"""get the total cpu usage at a certain time"""
cmd = f'cat /proc/stat |{d._filterType()} ^cpu'
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
r = re.compile(r'(?<!cpu)\d+')
toks = r.findall(result)
totalCpu = float(reduce(lambda x, y: int(x) + int(y), toks))
return totalCpu

def getSingCpuRate(self):
"""Get the cpu usage of a process"""
def getCpuCores(self):
"""get Android cpu cores"""
cmd = f'cat /sys/devices/system/cpu/online'
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
try:
nums = int(result.split('-')[1]) + 1
except:
nums = 1
return nums

def getIdleCpuStat(self):
"""get the idle cpu usage at a certain time"""
cmd = f'cat /proc/stat |{d._filterType()} ^cpu'
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
r = re.compile(r'(?<!cpu)\d+')
rList = result.split('\n')
IdleCpuList = []
IdleCpu = 0
for i in range(len(rList)):
toks = r.findall(rList[i])
IdleCpuList.append(toks[3])
IdleCpu = IdleCpu + float(reduce(lambda x, y: int(x) + int(y), IdleCpuList))
return IdleCpu

def getAndroidCpuRate(self):
"""get the Android cpu rate of a process"""
processCpuTime_1 = self.getprocessCpuStat()
totalCpuTime_1 = self.getTotalCpuStat()
idleCpuTime_1 = self.getIdleCpuStat()
devideCpuTime_1 = totalCpuTime_1 - idleCpuTime_1
time.sleep(1)
processCpuTime_2 = self.getprocessCpuStat()
totalCpuTime_2 = self.getTotalCpuStat()
idleCpuTime_2 = self.getIdleCpuStat()
devideCpuTime_2 = totalCpuTime_2 - idleCpuTime_2
appCpuRate = round(float((processCpuTime_2 - processCpuTime_1) / (totalCpuTime_2 - totalCpuTime_1) * 100), 2)
systemCpuRate = round(float((devideCpuTime_2 - devideCpuTime_1) / (totalCpuTime_2 - totalCpuTime_1) * 100), 2)

with open(f'{file().report_dir}/cpu_app.log', 'a+') as f:
f.write(f'{self.apm_time}={str(appCpuRate)}' + '\n')
with open(f'{file().report_dir}/cpu_sys.log', 'a+') as f:
f.write(f'{self.apm_time}={str(systemCpuRate)}' + '\n')

return appCpuRate, systemCpuRate

def getiOSCpuRate(self):
"""get the iOS cpu rate of a process, unit:%"""
apm = iosAPM(self.pkgName)
appCpuRate = round(float(apm.getPerformance(apm.cpu)), 2)
with open(f'{file().report_dir}/cpu_app.log', 'a+') as f:
f.write(f'{self.apm_time}={str(appCpuRate)}' + '\n')
return appCpuRate, 0

def getCpuRate(self):
"""Get the cpu rate of a process, unit:%"""
if self.platform == 'Android':
processCpuTime_1 = self.getprocessCpuStat()
totalCpuTime_1 = self.getTotalCpuStat()
time.sleep(1)
processCpuTime_2 = self.getprocessCpuStat()
totalCpuTime_2 = self.getTotalCpuStat()
cpuRate = round(float((processCpuTime_2 - processCpuTime_1) / (totalCpuTime_2 - totalCpuTime_1) * 100), 2)
appCpuRate, systemCpuRate = self.getAndroidCpuRate()
else:
apm = iosAPM(self.pkgName)
cpuRate = round(float(apm.getPerformance(apm.cpu)), 2)

with open(f'{file().report_dir}/cpu.log', 'a+') as f:
f.write(f'{self.apm_time}={str(cpuRate)}' + '\n')
return cpuRate
appCpuRate, systemCpuRate = self.getiOSCpuRate()
return appCpuRate, systemCpuRate


class MEM:
def __init__(self, pkgName, deviceId,platform='Android'):
def __init__(self, pkgName, deviceId, platform='Android'):
self.pkgName = pkgName
self.deviceId = deviceId
self.platform = platform
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')

def getAndroidMem(self):
"""Get the Android memory ,unit:MB"""
pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)
cmd = f'dumpsys meminfo {pid}'
output = adb.shell(cmd=cmd, deviceId=self.deviceId)
m_total = re.search(r'TOTAL\s*(\d+)', output)
m_native = re.search(r'Native Heap\s*(\d+)', output)
m_dalvik = re.search(r'Dalvik Heap\s*(\d+)', output)
totalPass = round(float(float(m_total.group(1))) / 1024, 2)
nativePass = round(float(float(m_native.group(1))) / 1024, 2)
dalvikPass = round(float(float(m_dalvik.group(1))) / 1024, 2)
return totalPass, nativePass, dalvikPass

def getiOSMem(self):
"""Get the iOS memory"""
apm = iosAPM(self.pkgName)
totalPass = round(float(apm.getPerformance(apm.memory)), 2)
nativePass = 0
dalvikPass = 0
return totalPass, nativePass, dalvikPass


def getProcessMem(self):
"""Get the Total、NativeHeap、NativeHeap"""
"""Get the app memory"""
if self.platform == 'Android':
pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)
cmd = f'dumpsys meminfo {pid}'
output = adb.shell(cmd=cmd, deviceId=self.deviceId)
m = re.search(r'TOTAL\s*(\d+)', output)
# m1 = re.search(r'Native Heap\s*(\d+)', output)
# m2 = re.search(r'Dalvik Heap\s*(\d+)', output)
time.sleep(1)
PSS = round(float(float(m.group(1))) / 1024, 2) # MB
# NativeHeap = round(float(float(m1.group(1))) / 1024, 2)
# DalvikHeap = round(float(float(m2.group(1))) / 1024, 2)
totalPass, nativePass, dalvikPass = self.getAndroidMem()
else:
apm = iosAPM(self.pkgName)
PSS = round(float(apm.getPerformance(apm.memory)), 2)
with open(f'{file().report_dir}/mem.log', 'a+') as f:
f.write(f'{self.apm_time}={str(PSS)}' + '\n')
return PSS
totalPass, nativePass, dalvikPass = self.getiOSMem()

with open(f'{file().report_dir}/mem_total.log', 'a+') as f:
f.write(f'{self.apm_time}={str(totalPass)}' + '\n')
if self.platform == 'Android':
with open(f'{file().report_dir}/mem_native.log', 'a+') as f:
f.write(f'{self.apm_time}={str(nativePass)}' + '\n')
with open(f'{file().report_dir}/mem_dalvik.log', 'a+') as f:
f.write(f'{self.apm_time}={str(dalvikPass)}' + '\n')
return totalPass, nativePass, dalvikPass


class Battery:
Expand All @@ -93,18 +154,21 @@ def __init__(self, deviceId, platform='Android'):
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')

def getBattery(self):
"""Get android battery"""
"""Get android battery info, unit:%"""
# Switch mobile phone battery to non-charging state
cmd = 'dumpsys battery set status 1'
adb.shell(cmd=cmd, deviceId=self.deviceId)
# Get phone battery
# Get phone battery info
cmd = 'dumpsys battery'
output = adb.shell(cmd=cmd, deviceId=self.deviceId)
battery = int(re.findall(u'level:\s?(\d+)', output)[0])
level = int(re.findall(u'level:\s?(\d+)', output)[0])
temperature = int(re.findall(u'temperature:\s?(\d+)', output)[0]) / 10
time.sleep(1)
with open(f'{file().report_dir}/battery.log', 'a+') as f:
f.write(f'{self.apm_time}={str(battery)}' + '\n')
return battery
with open(f'{file().report_dir}/battery_level.log', 'a+') as f:
f.write(f'{self.apm_time}={str(level)}' + '\n')
with open(f'{file().report_dir}/battery_tem.log', 'a+') as f:
f.write(f'{self.apm_time}={str(temperature)}' + '\n')
return level, temperature

def SetBattery(self):
"""Reset phone charging status"""
Expand All @@ -113,33 +177,44 @@ def SetBattery(self):

class Flow:

def __init__(self, pkgName, deviceId,platform='Android'):
def __init__(self, pkgName, deviceId, platform='Android'):
self.pkgName = pkgName
self.deviceId = deviceId
self.platform = platform
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')

def getAndroidNet(self):
"""Get Android upflow and downflow data, unit:KB"""
pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)
cmd = f'cat /proc/{pid}/net/dev |{d._filterType()} wlan0'
output_pre = adb.shell(cmd=cmd, deviceId=self.deviceId)
m_pre = re.search(r'wlan0:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)', output_pre)
sendNum_pre = round(float(float(m_pre.group(2)) / 1024), 2)
recNum_pre = round(float(float(m_pre.group(1)) / 1024), 2)
time.sleep(1)
output_final = adb.shell(cmd=cmd, deviceId=self.deviceId)
m_final = re.search(r'wlan0:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)', output_final)
sendNum_final = round(float(float(m_final.group(2)) / 1024), 2)
recNum_final = round(float(float(m_final.group(1)) / 1024), 2)
sendNum = round(float(sendNum_final - sendNum_pre), 2)
recNum = round(float(recNum_final - recNum_pre), 2)
return sendNum, recNum

def getiOSNet(self):
"""Get iOS upflow and downflow data"""
apm = iosAPM(self.pkgName)
apm_data = apm.getPerformance(apm.network)
sendNum = round(float(apm_data[1]), 2)
recNum = round(float(apm_data[0]), 2)
return sendNum, recNum


def getNetWorkData(self):
"""Get the upflow and downflow data"""
"""Get the upflow and downflow data, unit:KB"""
if self.platform == 'Android':
pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)
cmd = f'cat /proc/{pid}/net/dev |{d._filterType()} wlan0'
output_pre = adb.shell(cmd=cmd, deviceId=self.deviceId)
m_pre = re.search(r'wlan0:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)', output_pre)
sendNum_pre = round(float(float(m_pre.group(2)) / 1024), 2)
recNum_pre = round(float(float(m_pre.group(1)) / 1024), 2)
time.sleep(1)
output_final = adb.shell(cmd=cmd, deviceId=self.deviceId)
m_final = re.search(r'wlan0:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)', output_final)
sendNum_final = round(float(float(m_final.group(2)) / 1024), 2)
recNum_final = round(float(float(m_final.group(1)) / 1024), 2)
sendNum = round(float(sendNum_final - sendNum_pre), 2)
recNum = round(float(recNum_final - recNum_pre), 2)
sendNum, recNum = self.getAndroidNet()
else:
apm = iosAPM(self.pkgName)
apm_data = apm.getPerformance(apm.network)
sendNum = round(float(apm_data[1]), 2)
recNum = round(float(apm_data[0]), 2)
sendNum, recNum = self.getiOSNet()
with open(f'{file().report_dir}/upflow.log', 'a+') as f:
f.write(f'{self.apm_time}={str(sendNum)}' + '\n')
with open(f'{file().report_dir}/downflow.log', 'a+') as f:
Expand All @@ -148,34 +223,43 @@ def getNetWorkData(self):

class FPS:

def __init__(self, pkgName, deviceId,platform='Android'):
def __init__(self, pkgName, deviceId, platform='Android'):
self.pkgName = pkgName
self.deviceId = deviceId
self.platform = platform
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')

def getAndroidFps(self):
"""get Android Fps, unit:HZ"""
monitors = FPSMonitor(device_id=self.deviceId, package_name=self.pkgName, frequency=1,
start_time=TimeUtils.getCurrentTimeUnderline())
monitors.start()
fps, jank = monitors.stop()
with open(f'{file().report_dir}/fps.log', 'a+') as f:
f.write(f'{self.apm_time}={str(fps)}' + '\n')
with open(f'{file().report_dir}/jank.log', 'a+') as f:
f.write(f'{self.apm_time}={str(jank)}' + '\n')
return fps, jank

def getiOSFps(self):
"""get iOS Fps"""
apm = iosAPM(self.pkgName)
fps = int(apm.getPerformance(apm.fps))
with open(f'{file().report_dir}/fps.log', 'a+') as f:
f.write(f'{self.apm_time}={str(fps)}' + '\n')
return fps, 0

def getFPS(self):
"""get fps、jank"""
if self.platform == 'Android':
monitors = FPSMonitor(device_id=self.deviceId, package_name=self.pkgName, frequency=1,
start_time=TimeUtils.getCurrentTimeUnderline())
monitors.start()
fps, jank = monitors.stop()
with open(f'{file().report_dir}/fps.log', 'a+') as f:
f.write(f'{self.apm_time}={str(fps)}' + '\n')
with open(f'{file().report_dir}/jank.log', 'a+') as f:
f.write(f'{self.apm_time}={str(jank)}' + '\n')
return fps, jank
fps, jank = self.getAndroidFps()
else:
apm = iosAPM(self.pkgName)
fps = int(apm.getPerformance(apm.fps))
with open(f'{file().report_dir}/fps.log', 'a+') as f:
f.write(f'{self.apm_time}={str(fps)}' + '\n')
return fps,0
fps, jank = self.getiOSFps()
return fps, jank

class iosAPM():

def __init__(self, pkgName ,deviceId=tidevice.Device()):
def __init__(self, pkgName, deviceId=tidevice.Device()):
self.pkgName = pkgName
self.deviceId = deviceId
self.apm_time = datetime.datetime.now().strftime('%H:%M:%S.%f')
Expand All @@ -196,7 +280,7 @@ def callback(self,_type: DataType, value: dict):



def getPerformance(self,perfTpe:DataType):
def getPerformance(self, perfTpe:DataType):
perf = iosP.Performance(self.deviceId,[perfTpe])
perf_value = perf.start(self.pkgName, callback=self.callback)
if perfTpe == DataType.NETWORK:
Expand All @@ -210,9 +294,12 @@ def getPerformance(self,perfTpe:DataType):


if __name__ == '__main__':
apm = iosAPM("com.xxx.app.ios")
value = apm.getPerformance(apm.memory)
logger.info(value)
apm = CPU("com.xxx.app","ca6bd5a5")
cpu = apm.getprocessCpuStat()
total = apm.getTotalCpuStat()
rate = apm.getAndroidCpuRate()
logger.info(rate)




Loading

0 comments on commit 542281e

Please sign in to comment.