Skip to content

Commit

Permalink
update python api & lastest version check
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Nov 28, 2023
1 parent dfaa5bd commit 388ea5d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 54 deletions.
5 changes: 2 additions & 3 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@
* 界面如果不选择进程就点击Start收集,那么默认使用的是这个包名的主进程。
* 界面选择了app的某个进程收集,如果收集过程中将app杀掉,然后再恢复后自动使用的是主进程,有可能和你界面选择的进程不一致。


## 2️⃣0️⃣ Android/iOS最高支持的系统版本?

- Android: 13.0
- iOS: 16.5
- Android: 6.0+
- iOS: 12.0+
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,33 @@ python -m solox --host={ip} --port={port}
## 🏴󠁣󠁩󠁣󠁭󠁿Collect in python

```python
# solox version : >= 2.8.1
# solox version : >= 2.8.5
from solox.public.apm import AppPerformanceMonitor
from solox.public.common import Devices

d = Devices()
pids = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') # for android
processList = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') # for android
print(processList) # ['{pid}:{packagename}',...]

apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=False)
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=False, duration=0)
# apm = AppPerformanceMonitor(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)

# ************* Collect a performance parameter ************* #
cpu = apm.collectCpu() # %
memory = apm.collectMemory() # MB
flow = apm.collectFlow(wifi=True) # KB
network = apm.collectNetwork(wifi=True) # KB
fps = apm.collectFps() # HZ
battery = apm.collectBattery() # level:% temperature:°C current:mA voltage:mV power:w
gpu = apm.collectGpu() # % only supports ios

# ************* Collect all performance parameter ************* #

if __name__ == '__main__':
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=True)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS', deviceId='xxxx', noLog=False, record=False, collect_all=True)
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=True, duration=0)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS', deviceId='xxxx', noLog=False, record=False, collect_all=True, duration=0)
#duration: running time (second)
#record: record android screen
apm.collectAll() # will generate HTML report

Expand Down
36 changes: 20 additions & 16 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,42 @@ python -m solox --host={ip} --port={port}

```python

# solox version : >= 2.8.1
# solox version : >= 2.8.5
from solox.public.apm import AppPerformanceMonitor
from solox.public.common import Devices

d = Devices()
pids = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') # for android
processList = d.getPid(deviceId='ca6bd5a5', pkgName='com.bilibili.app.in') # for android
print(processList) # ['{pid}:{packagename}',...],一个app可能会有多个进程,如果需要指定pid,可以从这里获取

apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=False)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS') only supports one device
# surfaceview: False = gfxinfo (开发者 - GPU渲染模式 - adb shell dumpsys gfxinfo)
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True,
noLog=False, pid=None, record=False, collect_all=False)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS')
# surfaceview: 为False时是使用gfxinfo方式,需要在手机上设置:(手机开发者 - GPU渲染模式 - adb shell dumpsys gfxinfo)
# noLog : False (保存测试数据到log文件中)

# ************* Collect a performance parameter ************* #
# ************* 收集单个性能参数 ************* #
cpu = apm.collectCpu() # %
memory = apm.collectMemory() # MB
flow = apm.collectFlow(wifi=True) # KB
network = apm.collectNetwork(wifi=True) # KB
fps = apm.collectFps() # HZ
battery = apm.collectBattery() # level:% temperature:°C current:mA voltage:mV power:w
gpu = apm.collectGpu() # % 只支持ios

# ************* Collect all performance parameter ************* #
# ************* 收集所有性能参数 ************* #

if __name__ == '__main__':
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True, noLog=False, pid=None, record=False, collect_all=True)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS', deviceId='xxxx', noLog=False, record=False, collect_all=True)
# record: 是否录制
apm.collectAll() # will generate HTML report

# 在另外的python脚本中终止solox服务可以停止测试
if __name__ == '__main__': #必须要在__name__ == '__main__'里面执行
apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', deviceId='ca6bd5a5', surfaceview=True,
noLog=False, pid=None, record=False, collect_all=True, duration=0)
# apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in', platform='iOS', deviceId='xxxx', noLog=False, record=False, collect_all=True, duration=0)
#duration: 执行时长(秒),只有>0的时候才生效
#record: 是否录制
apm.collectAll() # 结束会生成测试报告

# 在另外的python脚本中可以主动终止solox服务,无需等待设置的执行时长结束
from solox.public.apm import initPerformanceService

initPerformanceService.stop() # stop solox
initPerformanceService.stop()
```

## 🏴󠁣󠁩󠁣󠁭󠁿使用API收集
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.8.4'
__version__ = '2.8.5'
31 changes: 23 additions & 8 deletions solox/public/apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,14 @@ def get_status(cls):

@classmethod
def start(cls):
config_json = json.loads(open(file=cls.CONIFG_PATH, mode='r').read())
config_json = dict()
config_json['run_switch'] = 'on'
with open(cls.CONIFG_PATH, "w") as file:
json.dump(config_json, file)

@classmethod
def stop(cls):
config_json = json.loads(open(file=cls.CONIFG_PATH, mode='r').read())
config_json = dict()
config_json['run_switch'] = 'off'
with open(cls.CONIFG_PATH, "w") as file:
json.dump(config_json, file)
Expand All @@ -447,7 +447,8 @@ class AppPerformanceMonitor(initPerformanceService):
"""for python api"""

def __init__(self, pkgName=None, platform=Platform.Android, deviceId=None,
surfaceview=True, noLog=True, pid=None, record=False, collect_all=False):
surfaceview=True, noLog=True, pid=None, record=False, collect_all=False,
duration=0):
self.pkgName = pkgName
self.deviceId = deviceId
self.platform = platform
Expand All @@ -456,6 +457,8 @@ def __init__(self, pkgName=None, platform=Platform.Android, deviceId=None,
self.pid = pid
self.record = record
self.collect_all = collect_all
self.duration = duration
self.end_time = time.time() + self.duration
d.devicesCheck(platform=self.platform, deviceid=self.deviceId, pkgname=self.pkgName)
self.start()

Expand All @@ -468,6 +471,8 @@ def collectCpu(self):
logger.info(f'cpu: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def collectMemory(self):
Expand All @@ -479,6 +484,8 @@ def collectMemory(self):
logger.info(f'memory: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def collectBattery(self):
Expand All @@ -493,20 +500,24 @@ def collectBattery(self):
logger.info(f'battery: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def collectFlow(self, wifi=True):
_flow = Network(self.pkgName, self.deviceId, self.platform, pid=self.pid)
def collectNetwork(self, wifi=True):
_network = Network(self.pkgName, self.deviceId, self.platform, pid=self.pid)
if self.noLog is False:
data = _flow.setAndroidNet(wifi=wifi)
data = _network.setAndroidNet(wifi=wifi)
f.record_net('pre', data[0], data[1])
result = {}
while self.get_status() == 'on':
upFlow, downFlow = _flow.getNetWorkData(wifi=wifi,noLog=self.noLog)
upFlow, downFlow = _network.getNetWorkData(wifi=wifi,noLog=self.noLog)
result = {'send': upFlow, 'recv': downFlow}
logger.info(f'network: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def collectFps(self):
Expand All @@ -518,6 +529,8 @@ def collectFps(self):
logger.info(f'fps: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def collectGpu(self):
Expand All @@ -531,6 +544,8 @@ def collectGpu(self):
logger.info(f'gpu: {result}')
if self.collect_all is False:
break
if self.duration > 0 and time.time() > self.end_time:
break
return result

def setPerfs(self):
Expand Down Expand Up @@ -597,7 +612,7 @@ def collectAll(self):
pool.apply_async(self.collectMemory)
pool.apply_async(self.collectBattery)
pool.apply_async(self.collectFps)
pool.apply_async(self.collectFlow)
pool.apply_async(self.collectNetwork)
pool.apply_async(self.collectGpu)
if self.record:
pool.apply_async(Scrcpy.start_record, (self.deviceId))
Expand Down
20 changes: 0 additions & 20 deletions solox/public/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,6 @@ def getPid(self, deviceId, pkgName):
logger.exception(e)
return processList

def getPidAdvance(self, deviceId, pkgName):
try:
pid_infos = os.popen(f"{self.adb} -s {deviceId} shell ps | {self.filterType()} {pkgName}").read()
pid_infos = pid_infos.strip() # 个别手机会出现单独一行的空格
logger.info(pid_infos)
real_pid = None
pid_infos = pid_infos.splitlines()
for pid in pid_infos:
pid = pid.strip()
if pid.split()[-1] == pkgName:
real_pid = pid.split()[1]
if not real_pid and pid_infos:
real_pid = pid_infos[0].split()[1]
logger.info("测试包获取到的pid是{}".format(real_pid))
return [real_pid]
except IndexError as e:
logger.error("获取到的pid信息是{}".format(pid_infos))
logger.exception(e)
return []

def checkPkgname(self, pkgname):
flag = True
replace_list = ['com.google']
Expand Down
19 changes: 19 additions & 0 deletions solox/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ <h5 class="modal-title">Connect to a Android device over Wi-Fi</h5>
}
});
});
versionCheck()
});

$('#debug-connect').click(function () {
Expand Down Expand Up @@ -465,6 +466,24 @@ <h5 class="modal-title">Connect to a Android device over Wi-Fi</h5>
});
}

function versionCheck(){
$.ajax({
url: Host + "/solox/version",
type: "GET",
async: true,
cache: false,
success: function (data) {
console.log(data)
if(data['lastest_version'] != data['current_version']){
SwalFire('info', 'New Version Found', 'Lastest Version: '+data['lastest_version']+' . Please execute [pip install -U solox].', 60000);
}
},
error: function(error){
console.log(error)
}
});
}

function initializeEnv(){
$.ajax({
url: Host + "/device/ids?platform="+platform,
Expand Down
13 changes: 13 additions & 0 deletions solox/view/apis.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import shutil
import time
import requests
import json
from flask import request, make_response
from logzero import logger
from flask import Blueprint
from solox import __version__
from solox.public.apm import CPU, Memory, Network, FPS, Battery, GPU, Target
from solox.public.apm_pk import CPU_PK, MEM_PK, Flow_PK, FPS_PK
from solox.public.common import Devices, File, Method, Install, Platform, Scrcpy
Expand Down Expand Up @@ -38,6 +41,16 @@ def setCookie():
resp.set_cookie('host_switch', host_switch)
return resp

@api.route('/solox/version', methods=['post', 'get'])
def version():
try:
pypi = json.loads(requests.get('https://pypi.org/pypi/solox/json').text)
version = pypi['info']['version']
result = {'status': 1, 'lastest_version': version, 'current_version': __version__}
except Exception as e:
logger.exception(e)
result = {'status': 0, 'msg': str(e)}
return result

@api.route('/apm/initialize', methods=['post', 'get'])
def initialize():
Expand Down

0 comments on commit 388ea5d

Please sign in to comment.