Skip to content

Commit

Permalink
fix #197
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa0128 committed Aug 10, 2023
1 parent c57a439 commit 14bda81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 59 deletions.
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
* Python API收集:record=True。
* Mac电脑录制视频,请检查Scrcpy是否安装成功,可以自行安装:brew install scrcpy。

## 1️⃣9️⃣ Android哪些指标以来app的进程需要存活
## 1️⃣9️⃣ Android哪些指标依赖app的进程需要存活

* Cpu、Memory、Network、FPS
* 界面如果不选择进程就点击Start收集,那么默认使用的是这个包名的主进程。
Expand Down
40 changes: 15 additions & 25 deletions solox/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import subprocess
import time
import os
import platform
import re
import webbrowser
import requests
import socket
import psutil
import sys
from view.apis import api
from view.pages import page
Expand Down Expand Up @@ -74,23 +73,14 @@ def ip() -> str:


def listen(port):
if platform.system() != 'Windows':
os.system("lsof -i:%s| grep LISTEN| awk '{print $2}'|xargs kill -9" % port)
else:
port_cmd = 'netstat -ano | findstr {}'.format(port)
r = os.popen(port_cmd)
r_data_list = r.readlines()
if len(r_data_list) == 0:
return
else:
pid_list = []
for line in r_data_list:
line = line.strip()
pid = re.findall(r'[1-9]\d*', line)
pid_list.append(pid[-1])
pid_set = list(set(pid_list))[0]
pid_cmd = 'taskkill -PID {} -F'.format(pid_set)
os.system(pid_cmd)
net_connections = psutil.net_connections()
conn = [c for c in net_connections if c.status == "LISTEN" and c.laddr.port == port]
if conn:
pid = conn[0].pid
logger.warning('Port {port} is used by process {pid}'.format(port, pid))
logger.info('you can start solox : python -m solox --host={ip} --port={port}')
return False
return True

def status(host: str, port: int):
r = requests.get('http://{}:{}'.format(host, port), timeout=2.0)
Expand All @@ -114,12 +104,12 @@ def start(host: str, port: int):

def main(host=ip(), port=50003):
try:
listen(port=port)
pool = multiprocessing.Pool(processes=2)
pool.apply_async(start, (host, port))
pool.apply_async(open_url, (host, port))
pool.close()
pool.join()
if listen(port=port):
pool = multiprocessing.Pool(processes=2)
pool.apply_async(start, (host, port))
pool.apply_async(open_url, (host, port))
pool.close()
pool.join()
except KeyboardInterrupt:
logger.info('stop solox success')
sys.exit()
Expand Down
65 changes: 33 additions & 32 deletions solox/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,42 +414,43 @@ <h5 class="modal-title">Connect to a Android device over Wi-Fi</h5>
});

$('.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 () {
if(platform == 'Android'){
$('.select-pid').empty();
}
if(lan == 'cn' ){
SwalLoading('初始化','正在获取该APP上的所有进程, 请您稍等!');
}else{
SwalLoading('Process initialization!','Initializing Process, please wait a mmoment.');
}

},
success: function (data) {
if(data['status'] != 1 ) {
if(platform == 'Android'){
$.ajax({
url: Host + "/package/pids",
type: "GET",
async: true,
cache: false,
data:{
platform:platform,
device:$('.select-device').val(),
pkgname:this.value
},
beforeSend: function () {
if(platform == 'Android'){
$('.select-pid').empty();
}
if(lan == 'cn' ){
SwalFire('warning', '警告','没有发现该app的进程,请检查app是否已经启动', 5000);
SwalLoading('初始化','正在获取该APP上的所有进程, 请您稍等!');
}else{
SwalFire('warning', 'Warning', data['msg'], 5000);
}
}else{
for(var i=0;i<data['pids'].length;i++){
$('.select-pid').append('<option>'+data['pids'][i]+'</option>')
SwalLoading('Process initialization!','Initializing Process, please wait a mmoment.');
}
},
success: function (data) {
if(data['status'] != 1 ) {
if(lan == 'cn' ){
SwalFire('warning', '警告','没有发现该app的进程,请检查app是否已经启动', 5000);
}else{
SwalFire('warning', 'Warning', data['msg'], 5000);
}
}else{
for(var i=0;i<data['pids'].length;i++){
$('.select-pid').append('<option>'+data['pids'][i]+'</option>')
}
swal.close();
}
swal.close();
}
}
});
});
}
});

function initializeAPM(){
Expand Down
2 changes: 1 addition & 1 deletion solox/view/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def getPackagePids():
result = {'status': 0, 'msg': 'No process found, please start the app first.'}
except Exception as e:
logger.exception(e)
result = {'status': 0, 'msg': 'No process foundd, please start the app first.'}
result = {'status': 0, 'msg': 'No process found, please start the app first.'}
return result

@api.route('/package/activity', methods=['post', 'get'])
Expand Down

0 comments on commit 14bda81

Please sign in to comment.