From 9a19e6ff23d971dea4d03dd97bc06d069e05fec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8=E6=9B=A6?= <18638672098@163.com> Date: Sun, 29 Sep 2024 16:38:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8Egraphical.target?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9B=B8=E5=85=B3=E6=9C=8D=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=90=8E=E8=BF=9B=E8=A1=8C=E8=BF=AD=E4=BB=A3?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kytuning/iterative_test.py | 47 ++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/kytuning/iterative_test.py b/src/kytuning/iterative_test.py index c3a7a6b..982a099 100644 --- a/src/kytuning/iterative_test.py +++ b/src/kytuning/iterative_test.py @@ -1,10 +1,27 @@ +import re import subprocess +def get_service_list(target): + """ + 获取target对应的服务 + """ + output = subprocess.check_output(['systemctl', 'list-dependencies', target]).decode().splitlines() + service_list = [] + + for line in output: + cleaned_line = re.sub(r'^[● │ └─ ├─]*', '', line).strip() + if cleaned_line.endswith(('target', 'service')): + service_list.append(cleaned_line) + return service_list + + def update_project_message(service): + """ + 更新project信息 + """ with open('./conf/kytuning.cfg', 'r') as file: lines = file.readlines() - new_lines = [] for line in lines: if line.startswith('project_message='): @@ -13,24 +30,34 @@ def update_project_message(service): new_lines.append(f'project_message="{new_project_message}"\n') else: new_lines.append(line) - with open('./conf/kytuning.cfg', 'w') as file: file.writelines(new_lines) + print(f'更新project_message配置信息成功') -def iterative_test(service_lsit): - for service in service_lsit: +def iterative_test(service_list): + """ + 迭代测试 + """ + # 需要服务倒叙运行 + print(f'因为服务的树结构所以需要倒叙运行相关服务') + for service in service_list[::-1]: systemctl_command = "systemctl start {}".format(service) - systemctl_result = subprocess.run(systemctl_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - text=True) + systemctl_result = subprocess.run(systemctl_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) print(systemctl_result.stdout) if systemctl_result.returncode: - return "systemctl start {} 命令执行失败".format(service) + print(f'systemctl start {service} 命令执行失败,启动下一服务') + continue + print(f'systemctl start {service} 命令运行成功') update_project_message(service) run_command = "cd /root/run_kytuning-ffdev/;bash run.sh" subprocess.run(run_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + print(f'启动{service}后,性能测试运行成功') -# egg:service_lsit = ['sshd.service', 'NetworkManager.service'] -service_lsit = [] -iterative_test(service_lsit) \ No newline at end of file +# 获取服务列表 +service_list = get_service_list('graphical.target') +print(f'graphical.target对应的targethe服务为:{service_list}') +# service_list = ['sshd.service', 'NetworkManager.service'] +# 拉起各项服务后测试 +iterative_test(service_list) -- Gitee