"""
"""
import subprocess
import json
import os
import sys
def run_command_and_get_output(command):
result = subprocess.run(
command,
shell=True,
check=True,
text=True,
capture_output=True
)
output = f"标准输出:\n{result.stdout}\n"
return {
"成功": True,
"返回码": result.returncode,
"输出": output,
}
def execute():
target_command = "build/output/bin/tile_fwk_utest --gtest_filter=CostModelTest.TestAttentionPostFunctional"
execution_result = run_command_and_get_output(target_command)
lines = []
mp = {}
for line in execution_result['输出'].split('\n'):
if 'latency' in line:
c_line = line.split(' ')[0]
latency = line.split(' ')[1]
op = c_line.split(':')[-1].strip(']')
if op not in mp:
mp[op] = []
mp[op].append(latency)
return mp
def compile():
target_command = "python3 build_ci.py -c -u --disable_auto_execute"
execution_result = run_command_and_get_output(target_command)
def changeAccLevel(new_value):
"""
:param file_path: 配置文件路径(如'tile_fwk_config.json')
:param key: 要修改的键(支持嵌套,如'log.level')
:param new_value: 新值
:return: 成功状态及提示信息
"""
file_path = f"src/configs/tile_fwk_config.json"
key = f"global.simulation.ACCURACY_LEVEL"
try:
with open(file_path, 'r', encoding='utf-8') as f:
config = json.load(f)
keys = key.split('.')
current = config
for i, k in enumerate(keys):
if i == len(keys) - 1:
current[k] = new_value
else:
current = current[k]
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(config, f, indent=4, ensure_ascii=False)
return {
"success": True,
"message": f"配置修改成功!键 '{key}' 已更新为: {new_value}"
}
except FileNotFoundError:
return {"success": False, "message": f"错误:文件 {file_path} 不存在"}
except json.JSONDecodeError:
return {"success": False, "message": f"错误:{file_path} 不是有效的JSON格式"}
except KeyError as e:
return {"success": False, "message": f"错误:键 '{e}' 不存在于配置中"}
except Exception as e:
return {"success": False, "message": f"未知错误:{str(e)}"}
def checkoutWorkDir():
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
target_dir = script_dir
for _ in range(4):
target_dir = os.path.dirname(target_dir)
os.chdir(target_dir)
if __name__ == "__main__":
checkoutWorkDir()
compile()
changeAccLevel(1)
res1 = execute()
changeAccLevel(2)
res2 = execute()
for key in res1.keys():
print(key)
print(res1[key])
print(res2[key])
print("!")