Skip to content

Commit

Permalink
fix #280
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed May 30, 2024
1 parent 8b8e1eb commit e0cd301
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<p align="center">
<a href="#">
<img src="https://cdn.nlark.com/yuque/0/2024/png/153412/1715927541315-fb4f7662-d8bb-4d3e-a712-13a3c3073ac8.png?x-oss-process=image%2Fformat%2Cwebp" alt="SoloX" width="130">
<img src="https://cdn.nlark.com/yuque/0/2024/png/153412/1715927541315-fb4f7662-d8bb-4d3e-a712-13a3c3073ac8.png?x-oss-process=image%2Fformat%2Cwebp" alt="SoloX" width="100">
</a>
<br>
</p>
Expand Down
7 changes: 3 additions & 4 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<p align="center">
<a href="#">
<img src="https://cdn.nlark.com/yuque/0/2024/png/153412/1715927541315-fb4f7662-d8bb-4d3e-a712-13a3c3073ac8.png?x-oss-process=image%2Fformat%2Cwebp" alt="SoloX" width="130">
<img src="https://cdn.nlark.com/yuque/0/2024/png/153412/1715927541315-fb4f7662-d8bb-4d3e-a712-13a3c3073ac8.png?x-oss-process=image%2Fformat%2Cwebp" alt="SoloX" width="100">
</a>
<br>
</p>
Expand Down Expand Up @@ -62,8 +62,7 @@ python -m solox --host={ip} --port={port}
## 🏴󠁣󠁩󠁣󠁭󠁿使用python收集

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

Expand All @@ -81,7 +80,7 @@ apm = AppPerformanceMonitor(pkgName='com.bilibili.app.in',platform='Android', de
cpu = apm.collectCpu() # %
memory = apm.collectMemory() # MB
memory_detail = apm.collectMemoryDetail() # MB
network = apm.collectNetwork(wifi=True) # KB , wifi=False时是收集移动网络,手机要切换数据流量
network = apm.collectNetwork(wifi=True) # KB , wifi=False时是收集移动数据流量,手机会自动关闭wifi切换到移动网络
fps = apm.collectFps() # HZ
battery = apm.collectBattery() # level:% temperature:°C current:mA voltage:mV power:w
gpu = apm.collectGpu() # % 安卓只支持高通芯片的手机
Expand Down
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = solox
author = Rafa Chen
author_email = [email protected]
summary = tool for apm
summary = tool for app performance
license = MIT
home_page = https://github.com/smart-test-ti/SoloX
description_file = README.md
Expand All @@ -12,6 +12,10 @@ classifier =
Operating System :: OS Independent
Programming Language :: Python :: 3

[files]
packages =
solox

[entry_points]
console_scripts =
solox = solox.__main__:main
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.9.0'
__version__ = '2.9.1'
6 changes: 5 additions & 1 deletion solox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from logzero import logger
import platform
import fire as fire
# import argparse
from solox import __version__

def checkPyVer():
versions = platform.python_version().split('.')
Expand All @@ -12,7 +14,9 @@ def checkPyVer():
return True

if __name__ == '__main__':
# ap = argparse.ArgumentParser(
# formatter_class=argparse.ArgumentDefaultsHelpFormatter)
check = checkPyVer()
if check:
from solox.web import main
fire.Fire(main)
fire.Fire(main)
49 changes: 37 additions & 12 deletions solox/public/apm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,56 @@ def getTotalCpuStat(self):
for i in range(1, 8):
totalCpu += float(toks[i])
return float(totalCpu)

def getSysCpuStat(self):
"""get the total cpu usage at a certain time"""
def getCpuCoreStat(self):
"""get the core cpu usage at a certain time"""
cmd = 'cat /proc/stat |{} ^cpu'.format(d.filterType())
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
r = re.compile(r'(?<!cpu\d+)')
toks = r.findall(result)
idleCpu = float(toks[4])
logger.info(idleCpu)
sysCpu = self.getTotalCpuStat() - idleCpu
return sysCpu
coreCpu = 0
coreCpuList = []
lines = result.split('\n')
lines.pop(0)
for line in lines:
toks = line.split()
if toks[1] in ['', ' ']:
toks.pop(1)
for i in range(1, 8):
coreCpu += float(toks[i])
coreCpuList.append(coreCpu)
coreCpu = 0
print(coreCpuList)
return coreCpuList

def getCoreIdleCpuStat(self):
"""get the core idel cpu usage at a certain time"""
cmd = 'cat /proc/stat |{} ^cpu'.format(d.filterType())
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
idleCpuList = []
idleCpu = 0
lines = result.split('\n')
lines.pop(0)
for line in lines:
toks = line.split()
if toks[1] in ['', ' ']:
toks.pop(1)
idleCpu += float(toks[4])
idleCpuList.append(idleCpu)
idleCpu = 0
return idleCpuList

def getIdleCpuStat(self):
"""get the total cpu usage at a certain time"""
cmd = 'cat /proc/stat |{} ^cpu'.format(d.filterType())
result = adb.shell(cmd=cmd, deviceId=self.deviceId)
ileCpu = 0
idleCpu = 0
lines = result.split('\n')
lines.pop(0)
for line in lines:
toks = line.split()
if toks[1] in ['', ' ']:
toks.pop(1)
ileCpu += float(toks[4])
return ileCpu
idleCpu += float(toks[4])
return idleCpu

def getAndroidCpuRate(self, noLog=False):
"""get the Android cpu rate of a process"""
Expand Down
1 change: 1 addition & 0 deletions solox/public/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ def _settings(cls, request):
content['netdataRecvWarning'] = (0, request.cookies.get('netdataRecvWarning'))[request.cookies.get('netdataRecvWarning') not in [None, 'NaN']]
content['netdataSendWarning'] = (0, request.cookies.get('netdataSendWarning'))[request.cookies.get('netdataSendWarning') not in [None, 'NaN']]
content['betteryWarning'] = (0, request.cookies.get('betteryWarning'))[request.cookies.get('betteryWarning') not in [None, 'NaN']]
content['gpuWarning'] = (0, request.cookies.get('gpuWarning'))[request.cookies.get('gpuWarning') not in [None, 'NaN']]
content['duration'] = (0, request.cookies.get('duration'))[request.cookies.get('duration') not in [None, 'NaN']]
content['solox_host'] = ('', request.cookies.get('solox_host'))[request.cookies.get('solox_host') not in [None, 'NaN']]
content['host_switch'] = request.cookies.get('host_switch')
Expand Down
8 changes: 4 additions & 4 deletions solox/public/report_template/android.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
<span class="input-group-text">
<strong>APP</strong>
</span>
<input type="text" class="form-control" value="{{ app }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ app }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>Platform</strong>
</span>
<input type="text" class="form-control" value="{{ platform }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ platform }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>Device</strong>
</span>
<input type="text" class="form-control" value="{{ devices }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ devices }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>CTime</strong>
</span>
<input type="text" class="form-control" value="{{ ctime }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ ctime }}" autocomplete="off">
</div>
</div>
</header>
Expand Down
8 changes: 4 additions & 4 deletions solox/public/report_template/ios.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
<span class="input-group-text">
<strong>APP</strong>
</span>
<input type="text" class="form-control" value="{{ app }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ app }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>Platform</strong>
</span>
<input type="text" class="form-control" value="{{ platform }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ platform }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>Device</strong>
</span>
<input type="text" class="form-control" value="{{ devices }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ devices }}" autocomplete="off">
</div>
<div class="input-group" style="margin-left: 10px;">
<span class="input-group-text">
<strong>CTime</strong>
</span>
<input type="text" class="form-control" value="{{ ctime }}" autocomplete="off">
<input type="text" class="form-control" disabled value="{{ ctime }}" autocomplete="off">
</div>
</div>
</header>
Expand Down
6 changes: 3 additions & 3 deletions solox/templates/analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
{% if apm_data.disk_flag == True %}
<div class="card disk-card mt-3">
<div class="card-header">
<div class='card-title'>{% if lan == 'cn' %} 磁盘使用 (MB) {% else %} Disk Usage (KB) {% endif %}</div>
<div class='card-title'>{% if lan == 'cn' %} 磁盘 (KB) {% else %} Disk Usage (KB) {% endif %}</div>
<div class="card-actions btn-actions">
<a class="btn" onclick="initDiskCharts()">
<span class="spinner-border spinner-border-sm me-2" id="disk_spinner" role="status" style="display: none;"></span>
Expand All @@ -562,7 +562,7 @@
</div>
{% endif %}
</div>

{% if platform == 'Android'%}
<!-- Disk Usage -->
<div class="row row-deck row-cards card-disk mb-3">
<div class="col-lg-6">
Expand Down Expand Up @@ -700,7 +700,7 @@ <h3 class="card-title">
</table>
</div>
</div>

{% endif %}
<div class="modal modal-blur fade" id="modal-compare" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
Expand Down
9 changes: 7 additions & 2 deletions solox/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ <h1 class="navbar-brand navbar-brand-autodark d-none-navbar-horizontal pe-0 pe-m
<div class="nav-item dropdown d-none d-md-flex me-3">
<a href="/?platform=Android&lan={{ lan }}" class="btn btn-pill w-100" >
<svg t="1684145849174" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="12372" width="50" height="50"><path d="M512 64C264.576 64 64 264.576 64 512s200.576 448 448 448 448-200.576 448-448S759.424 64 512 64z" fill="#94BFFF" p-id="12373"></path><path d="M498.56 519.666a10.668 10.668 0 0 1 0-15.332c21.718-21.126 84.97-82.904 148.374-147.128 14.336-14.516 19.86-35.152 7.744-51.408-4.972-6.654-11.584-14.192-20.352-22.284-11.926-11.014-23.296-18.38-32.768-23.28-15.51-8.02-33.686-3.928-47.766 6.24-110.25 79.572-185.43 165.484-221.802 211.612-15.98 20.29-15.98 47.538 0 67.828 36.372 46.128 111.552 132.04 221.802 211.614 14.08 10.166 32.256 14.256 47.766 6.238 9.472-4.9 20.842-12.266 32.768-23.28 8.768-8.092 15.38-15.63 20.352-22.284 12.116-16.256 6.592-36.892-7.744-51.406-63.404-64.226-126.656-126.004-148.374-147.13z" fill="#1677FF" p-id="12374"></path></svg>
{% if lan == 'cn' %} 普通模式 {% else %} Normal Model {% endif %}
{% if lan == 'cn' %} 普通模式 {% else %} Normal Mode {% endif %}
</a>
</div>
{% else %}
<div class="nav-item dropdown d-none d-md-flex me-3">
<a href="/pk?model=2-devices&lan={{ lan }}" class="btn btn-pill w-100" >
<svg t="1661854041585" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10784" width="2000" height="2000"><path d="M17.408 862.208a450.56 129.024 0 1 0 901.12 0 450.56 129.024 0 1 0-901.12 0Z" fill="#EEF2FF" p-id="10785"></path><path d="M509.952 880.64H75.776c-17.408 0-30.72-13.312-30.72-30.72V293.888c0-64.512 52.224-116.736 116.736-116.736h522.24c35.84 0 64.512 28.672 64.512 64.512v400.384C748.544 774.144 642.048 880.64 509.952 880.64z" fill="#70D4FF" p-id="10786"></path><path d="M764.928 880.64H212.992c-17.408 0-30.72-13.312-30.72-30.72V60.416h755.712c35.84 0 64.512 28.672 64.512 64.512v517.12C1002.496 774.144 896 880.64 764.928 880.64z" fill="#4E8EFF" p-id="10787"></path><path d="M555.008 403.456c0 20.48-7.168 35.84-22.528 48.128-14.336 11.264-30.72 16.384-51.2 16.384h-28.672v48.128c0 9.216 2.048 15.36 6.144 19.456 4.096 4.096 11.264 5.12 21.504 5.12V563.2H373.76v-22.528c15.36 0 23.552-8.192 23.552-24.576V389.12c0-16.384-8.192-24.576-23.552-24.576v-22.528h109.568c19.456 0 35.84 5.12 49.152 15.36 14.336 12.288 22.528 27.648 22.528 46.08z m-59.392 2.048c0-26.624-11.264-39.936-34.816-39.936h-9.216v80.896h11.264c13.312 0 22.528-3.072 26.624-10.24 4.096-7.168 6.144-17.408 6.144-30.72zM800.768 563.2h-60.416c-8.192-7.168-15.36-15.36-21.504-22.528l-57.344-74.752v50.176c0 16.384 9.216 24.576 26.624 24.576V563.2H584.704v-22.528c16.384 0 23.552-8.192 23.552-24.576V389.12c0-16.384-8.192-24.576-24.576-24.576v-22.528h105.472v22.528c-17.408 0-26.624 8.192-26.624 24.576v50.176l39.936-37.888c13.312-12.288 19.456-21.504 19.456-27.648 0-5.12-5.12-8.192-15.36-8.192v-22.528h81.92v22.528c-9.216 0-15.36 1.024-20.48 4.096-3.072 2.048-8.192 6.144-15.36 13.312L705.536 430.08l70.656 94.208c7.168 9.216 15.36 15.36 25.6 16.384V563.2z" fill="#FFFFFF" p-id="10788"></path></svg>
{% if lan == 'cn' %} 比对模式 {% else %} PK Model {% endif %}
{% if lan == 'cn' %} 比对模式 {% else %} PK Mode {% endif %}
</a>
</div>
{% endif %}
Expand Down Expand Up @@ -211,6 +211,10 @@ <h2 class="offcanvas-title" id="offcanvasEndLabel">
<label class="form-label">{% if lan == 'cn' %} 下行流量告警值 {% else %} Recv network data warning value {% endif %}</label>
<input id="downflow_warning_value" type="text" class="form-control" placeholder="Input placeholder" value="{{ settings.netdataRecvWarning }}">
</div>
<div class="mb-3">
<label class="form-label">{% if lan == 'cn' %} GPU告警值 {% else %} GPU warning value {% endif %}</label>
<input id="gpu_warning_value" type="text" class="form-control" placeholder="Input placeholder" value="{{ settings.gpuWarning }}">
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -385,6 +389,7 @@ <h2 class="offcanvas-title" id="offcanvasEndLabel">
netdataRecvWarning:parseInt($('#down_warning_value').val()),
netdataSendWarning:parseInt($('#upflow_warning_value').val()),
betteryWarning:parseInt($('#battery_warning_value').val()),
gpuWarning:parseInt($('#gpu_warning_value').val()),
duration:parseInt($('#duration').val()),
solox_host: $('#host').val(),
host_switch:host_switch
Expand Down
Loading

0 comments on commit e0cd301

Please sign in to comment.