From 40b3f674333bcc4abc72384621f28f0cbe98c0f2 Mon Sep 17 00:00:00 2001 From: chenhq Date: Wed, 19 Apr 2023 17:27:07 +0800 Subject: [PATCH] v2.5.9 --- README.md | 9 +++-- README.zh.md | 7 +++- solox/__init__.py | 2 +- solox/public/apm.py | 44 ++++++++++++++----------- solox/public/common.py | 10 +++--- solox/templates/base.html | 2 +- solox/templates/index.html | 67 ++++++++++++++++++++++++++++++++++---- solox/view/apis.py | 38 +++++++++++++++++---- 8 files changed, 139 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index fef08db..84f7efb 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ pip install -U solox pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple -U solox ``` -💡 If your network is unable to download through [pip install -U solox], please try using mirrors to download, but the download of Solox may not be the latest version. +💡 If your network is unable to download through [pip install -U solox], please try using mirrors to download, but the download of SoloX may not be the latest version. ## 🚀Startup SoloX @@ -66,9 +66,14 @@ python -m solox --host={ip} --port={port} ```python from solox.public.apm import APM +from solox.public.common import Devices + # solox version >= 2.1.2 -apm = APM(pkgName='com.bilibili.app.in',deviceId='ca6bd5a5',platform='Android', surfaceview=True, noLog=True) +d = Devices() +pids = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') + +apm = APM(pkgName='com.bilibili.app.in',deviceId='ca6bd5a5',platform='Android', surfaceview=True, noLog=True, pid=None) # apm = APM(pkgName='com.bilibili.app.in', platform='iOS') only supports one device # surfaceview: False = gfxinfo (Developer - GPU rendering mode - adb shell dumpsys gfxinfo) # noLog : False (Save test data to log file) diff --git a/README.zh.md b/README.zh.md index 276efaf..c2c372a 100644 --- a/README.zh.md +++ b/README.zh.md @@ -66,9 +66,14 @@ python -m solox --host={ip} --port={port} ```python from solox.public.apm import APM +from solox.public.common import Devices + # solox version >= 2.1.2 -apm = APM(pkgName='com.bilibili.app.in',deviceId='ca6bd5a5',platform='Android', surfaceview=True, noLog=True) +d = Devices() +pids = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') + +apm = APM(pkgName='com.bilibili.app.in',deviceId='ca6bd5a5',platform='Android', surfaceview=True, noLog=True, pid=None) # apm = APM(pkgName='com.bilibili.app.in', platform='iOS') only supports one device # surfaceview: False = gfxinfo (Developer - GPU rendering mode - adb shell dumpsys gfxinfo) # noLog : False (Save test data to log file) diff --git a/solox/__init__.py b/solox/__init__.py index 523d82e..65180da 100644 --- a/solox/__init__.py +++ b/solox/__init__.py @@ -2,4 +2,4 @@ from __future__ import absolute_import -__version__ = '2.5.8' +__version__ = '2.5.9' diff --git a/solox/public/apm.py b/solox/public/apm.py index 638eaa8..23ef2e1 100644 --- a/solox/public/apm.py +++ b/solox/public/apm.py @@ -24,15 +24,17 @@ class Target: class CPU(object): - def __init__(self, pkgName, deviceId, platform='Android'): + def __init__(self, pkgName, deviceId, platform=Platform.Android, pid=None): self.pkgName = pkgName self.deviceId = deviceId self.platform = platform + self.pid = pid + if self.pid is None and self.platform == Platform.Android: + self.pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)[0].split(':')[0] def getprocessCpuStat(self): """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' + cmd = f'cat /proc/{self.pid}/stat' result = adb.shell(cmd=cmd, deviceId=self.deviceId) r = re.compile("\\s+") toks = r.split(result) @@ -70,7 +72,7 @@ def getSysCpuStat(self): sysCpu = self.getTotalCpuStat() - ileCpu return sysCpu - def getAndroidCpuRate(self, sueApi=False): + def getAndroidCpuRate(self, noLog=False): """get the Android cpu rate of a process""" processCpuTime_1 = self.getprocessCpuStat() totalCpuTime_1 = self.getTotalCpuStat() @@ -81,19 +83,19 @@ def getAndroidCpuRate(self, sueApi=False): sysCpuTime_2 = self.getSysCpuStat() appCpuRate = round(float((processCpuTime_2 - processCpuTime_1) / (totalCpuTime_2 - totalCpuTime_1) * 100), 2) sysCpuRate = round(float((sysCpuTime_2 - sysCpuTime_1) / (totalCpuTime_2 - totalCpuTime_1) * 100), 2) - if sueApi is False: + if noLog is False: apm_time = datetime.datetime.now().strftime('%H:%M:%S') f.add_log(os.path.join(f.report_dir,'cpu_app.log'), apm_time, appCpuRate) f.add_log(os.path.join(f.report_dir,'cpu_sys.log'), apm_time, sysCpuRate) return appCpuRate, sysCpuRate - def getiOSCpuRate(self, sueApi=False): + def getiOSCpuRate(self, noLog=False): """get the iOS cpu rate of a process, unit:%""" apm = iosAPM(self.pkgName) appCpuRate = round(float(apm.getPerformance(apm.cpu)[0]), 2) sysCpuRate = round(float(apm.getPerformance(apm.cpu)[1]), 2) - if sueApi is False: + if noLog is False: apm_time = datetime.datetime.now().strftime('%H:%M:%S') f.add_log(os.path.join(f.report_dir,'cpu_app.log'), apm_time, appCpuRate) f.add_log(os.path.join(f.report_dir,'cpu_sys.log'), apm_time, sysCpuRate) @@ -106,15 +108,17 @@ def getCpuRate(self, noLog=False): class MEM(object): - def __init__(self, pkgName, deviceId, platform=Platform.Android): + def __init__(self, pkgName, deviceId, platform=Platform.Android, pid=None): self.pkgName = pkgName self.deviceId = deviceId self.platform = platform + self.pid = pid + if self.pid is None and self.platform == Platform.Android: + self.pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)[0].split(':')[0] def getAndroidMem(self): """Get the Android memory ,unit:MB""" - pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId) - cmd = f'dumpsys meminfo {pid}' + cmd = f'dumpsys meminfo {self.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) @@ -200,16 +204,18 @@ def recoverBattery(self): class Flow(object): - def __init__(self, pkgName, deviceId, platform=Platform.Android): + def __init__(self, pkgName, deviceId, platform=Platform.Android, pid=None): self.pkgName = pkgName self.deviceId = deviceId self.platform = platform + self.pid = pid + if self.pid is None and self.platform == Platform.Android: + self.pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId)[0].split(':')[0] def getAndroidNet(self, wifi=True): """Get Android send/recv data, unit:KB wlan0/rmnet0""" net = 'wlan0' if wifi else 'rmnet0' - pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId) - cmd = f'cat /proc/{pid}/net/dev |{d.filterType()} {net}' + cmd = f'cat /proc/{self.pid}/net/dev |{d.filterType()} {net}' output_pre = adb.shell(cmd=cmd, deviceId=self.deviceId) m_pre = re.search(r'{}:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)'.format(net), output_pre) sendNum_pre = round(float(float(m_pre.group(2)) / 1024), 2) @@ -225,8 +231,7 @@ def getAndroidNet(self, wifi=True): def setAndroidNet(self, wifi=True): net = 'wlan0' if wifi else 'rmnet0' - pid = d.getPid(pkgName=self.pkgName, deviceId=self.deviceId) - cmd = f'cat /proc/{pid}/net/dev |{d.filterType()} {net}' + cmd = f'cat /proc/{self.pid}/net/dev |{d.filterType()} {net}' output_pre = adb.shell(cmd=cmd, deviceId=self.deviceId) m = re.search(r'{}:\s*(\d+)\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)'.format(net), output_pre) sendNum = round(float(float(m.group(2)) / 1024), 2) @@ -339,23 +344,24 @@ def getPerformance(self, perfTpe: DataType): class APM(object): """for python api""" - def __init__(self, pkgName, deviceId='', platform=Platform.Android, surfaceview=True, noLog=True): + def __init__(self, pkgName, deviceId=None, platform=Platform.Android, surfaceview=True, noLog=True, pid=None): self.pkgName = pkgName self.deviceId = deviceId self.platform = platform self.surfaceview = surfaceview self.noLog = noLog + self.pid = pid d.devicesCheck(platform=self.platform, deviceid=self.deviceId, pkgname=self.pkgName) def collectCpu(self): - _cpu = CPU(self.pkgName, self.deviceId, self.platform) + _cpu = CPU(self.pkgName, self.deviceId, self.platform, pid=self.pid) appCpuRate, systemCpuRate = _cpu.getCpuRate(noLog=self.noLog) result = {'appCpuRate': appCpuRate, 'systemCpuRate': systemCpuRate} logger.info(f'cpu: {result}') return result def collectMemory(self): - _memory = MEM(self.pkgName, self.deviceId, self.platform) + _memory = MEM(self.pkgName, self.deviceId, self.platform, pid=self.pid) totalPass, nativePass, dalvikPass = _memory.getProcessMem(noLog=self.noLog) result = {'totalPass': totalPass, 'nativePass': nativePass, 'dalvikPass': dalvikPass} logger.info(f'memory: {result}') @@ -372,7 +378,7 @@ def collectBattery(self): return result def collectFlow(self, wifi=True): - _flow = Flow(self.pkgName, self.deviceId, self.platform) + _flow = Flow(self.pkgName, self.deviceId, self.platform, pid=self.pid) upFlow, downFlow = _flow.getNetWorkData(wifi=wifi,noLog=self.noLog) result = {'upFlow': upFlow, 'downFlow': downFlow} logger.info(f'network: {result}') diff --git a/solox/public/common.py b/solox/public/common.py index 8f34d91..876ddc1 100644 --- a/solox/public/common.py +++ b/solox/public/common.py @@ -75,12 +75,14 @@ def getIdbyDevice(self, deviceinfo, platform): def getPid(self, deviceId, pkgName): """Get the pid corresponding to the Android package name""" result = os.popen(f"{self.adb} -s {deviceId} shell ps -ef | {self.filterType()} {pkgName}").readlines() - flag = len(result) > 0 try: - pid = (0, result[0].split()[1])[flag] + processList = [] + for process in result: + processInfo = '{}:{}'.format(process.split()[1],process.split()[7]) + processList.append(processInfo) except Exception: - pid = None - return pid + logger.error('no pid found') + return processList def checkPkgname(self, pkgname): flag = True diff --git a/solox/templates/base.html b/solox/templates/base.html index d312ec9..983dc24 100644 --- a/solox/templates/base.html +++ b/solox/templates/base.html @@ -136,7 +136,7 @@

  • - {% if lan == 'cn' %} 版本 {% else %} Releases {% endif %} . V2.5.8 + {% if lan == 'cn' %} 版本 {% else %} Releases {% endif %} . V2.5.9
  • diff --git a/solox/templates/index.html b/solox/templates/index.html index a1c813b..b8ac0c6 100644 --- a/solox/templates/index.html +++ b/solox/templates/index.html @@ -93,7 +93,7 @@