Skip to content

Commit

Permalink
v2.5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Apr 19, 2023
1 parent 938681f commit 40b3f67
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 40 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.5.8'
__version__ = '2.5.9'
44 changes: 25 additions & 19 deletions solox/public/apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}')
Expand All @@ -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}')
Expand Down
10 changes: 6 additions & 4 deletions solox/public/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion solox/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h2 class="page-title">
</li>
<li class="list-inline-item">
<a href="https://github.com/smart-test-ti/SoloX/releases" target="_blank" class="link-secondary" rel="noopener">
{% if lan == 'cn' %} 版本 {% else %} Releases {% endif %} . V2.5.8
{% if lan == 'cn' %} 版本 {% else %} Releases {% endif %} . V2.5.9
</a>
</li>
</ul>
Expand Down
67 changes: 61 additions & 6 deletions solox/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h6 class="dropdown-header">{% if lan == 'cn' %} 基础信息 {% else %} Base In
<select class="select-device select2-selection--single" data-placeholder="Please select a device"></select>
{% endif %}
</div>
<div class="input-group" style="width: 93%;margin-left: 10px;">
<div class="input-group mb-3" style="width: 93%;margin-left: 10px;">
<div class="input-group-text">
<svg t="1645171258689" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2225" width="2000" height="2000"><path d="M352 96H224c-70.4 0-128 57.6-128 128v128c0 70.4 57.6 128 128 128h192c35.2 0 64-28.8 64-64V224c0-70.4-57.6-128-128-128z m64 319.9l-0.1 0.1H224c-17 0-33-6.7-45.1-18.9S160 369 160 352V224c0-17 6.7-33 18.9-45.1S207 160 224 160h128c17 0 33 6.7 45.1 18.9S416 207 416 224v191.9zM800 96H672c-70.4 0-128 57.6-128 128v192c0 35.2 28.8 64 64 64h192c70.4 0 128-57.6 128-128V224c0-70.4-57.6-128-128-128z m64 256c0 17-6.7 33-18.9 45.1S817 416 800 416H608.1l-0.1-0.1V224c0-17 6.7-33 18.9-45.1S655 160 672 160h128c17 0 33 6.7 45.1 18.9S864 207 864 224v128zM416 544H224c-70.4 0-128 57.6-128 128v128c0 70.4 57.6 128 128 128h128c70.4 0 128-57.6 128-128V608c0-35.2-28.8-64-64-64z m0 256c0 17-6.7 33-18.9 45.1S369 864 352 864H224c-17 0-33-6.7-45.1-18.9S160 817 160 800V672c0-17 6.7-33 18.9-45.1S207 608 224 608h191.9l0.1 0.1V800zM800 544H608c-35.2 0-64 28.8-64 64v192c0 70.4 57.6 128 128 128h128c70.4 0 128-57.6 128-128V672c0-70.4-57.6-128-128-128z m64 256c0 17-6.7 33-18.9 45.1S817 864 800 864H672c-17 0-33-6.7-45.1-18.9S608 817 608 800V608.1l0.1-0.1H800c17 0 33 6.7 45.1 18.9S864 655 864 672v128z" fill="#1875F0" p-id="2226"></path></svg>
</div>
Expand All @@ -103,6 +103,18 @@ <h6 class="dropdown-header">{% if lan == 'cn' %} 基础信息 {% else %} Base In
<select class="select-app select2-selection--single" data-placeholder="Please select a package"></select>
{% endif %}
</div>
{% if platform == 'Android' %}
<div class="input-group" style="width: 93%;margin-left: 10px;">
<div class="input-group-text">
<svg t="1681890999535" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5737" width="50" height="50"><path d="M512 64.303538c-247.254314 0-447.696462 200.438055-447.696462 447.696462s200.442148 447.696462 447.696462 447.696462c247.258407 0 447.696462-200.438055 447.696462-447.696462S759.258407 64.303538 512 64.303538zM512 914.925792c-222.532259 0-402.926816-180.394556-402.926816-402.926816 0-222.532259 180.394556-402.926816 402.926816-402.926816 222.527143 0 402.926816 180.394556 402.926816 402.926816C914.926816 734.531236 734.528166 914.925792 512 914.925792zM512 243.382123c-148.352793 0-268.617877 120.265084-268.617877 268.617877s120.265084 268.617877 268.617877 268.617877 268.617877-120.265084 268.617877-268.617877S660.353816 243.382123 512 243.382123z" p-id="5738" data-spm-anchor-id="a313x.7781069.0.i3" class="selected" fill="#d81e06"></path></svg>
</div>
{% if lan == 'cn' %}
<select class="select-pid select2-selection--single" data-placeholder="请选择一个进程"></select>
{% else %}
<select class="select-pid select2-selection--single" data-placeholder="Please select a process"></select>
{% endif %}
</div>
{% endif %}
<div class="card" style="margin-top: 13px;">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs" data-bs-toggle="tabs">
Expand Down Expand Up @@ -311,6 +323,44 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
});
});

$('.select-app').change(function() {
$.ajax({
url: Host + "/package/pids",
type: "GET",
async: true,
cache: false,
data:{
platform:platform,
device:$('.select-device').val(),
pkgname:this.value
},
beforeSend: function () {
$('.select-pid').empty();
$('.select-pid').append('<option></option>');
if(lan == 'cn' ){
SwalLoading('初始化','正在获取该APP上的所有进程, 请您稍等!');
}else{
SwalLoading('Process initialization!','Initializing Process, please wait a mmoment.');
}

},
success: function (data) {
if(data['status'] != 1 ) {
if(lan == 'cn' ){
SwalFire('error', '连接失败','请检查当前移动设备的是否连接了PC端', 2000);
}else{
SwalFire('error', 'Connet failed !', 'No pid found', 2000);
}
}else{
for(var i=0;i<data['pids'].length;i++){
$('.select-pid').append('<option>'+data['pids'][i]+'</option>')
}
swal.close();
}
}
});
});


function initializeAPM(){
$.ajax({
Expand Down Expand Up @@ -381,7 +431,8 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
model:'normal',
platform:platform,
pkgname:pkgname,
device:device
device:device,
process:$('.select-pid').val()
},
beforeSend: function () {
window.clearTimeout(timerQ);
Expand Down Expand Up @@ -510,7 +561,8 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
model:'normal',
platform:platform,
pkgname:pkgname,
device:device
device:device,
process:$('.select-pid').val()
},
beforeSend: function () {
window.clearTimeout(timerQ);
Expand Down Expand Up @@ -562,7 +614,8 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
pkgname:pkgname,
device:device,
wifi_switch: net_switch,
type: type
type: type,
process:$('.select-pid').val()
},
success: function (data) {
if(data['status'] != 1){
Expand All @@ -586,7 +639,8 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
platform:platform,
pkgname:pkgname,
device:device,
wifi_switch: net_switch
wifi_switch: net_switch,
process:$('.select-pid').val()
},
beforeSend: function () {
window.clearTimeout(timerQ);
Expand Down Expand Up @@ -1254,7 +1308,8 @@ <h2 class="offcanvas-title" id="offcanvasBottomLabel">Error Log</h2>
model:'normal',
app:$('.select-app').val(),
devices:$('.select-device').val(),
wifi_switch:wifi_switch
wifi_switch:wifi_switch,
process:$('.select-pid').val()
},
beforeSend: function () {

Expand Down
Loading

0 comments on commit 40b3f67

Please sign in to comment.