feat(projectrans): 主进程 PROF 自动落盘 + 编译耗时统计 + 分析脚本升级

- Projectrans.py 入口包 cProfile,整次编译自动导出 main_prof_{pid}.prof 到 ./PROF;成功/失败均输出 [TIMING] 总耗时(stderr)并落盘 main_time.txt
- Config.py 新增 --asan(透传 TPC_ASAN=1)+ 每次编译自动清理 PROF 目录 *.prof
- PROF/1.py 升级为综合报告(tottime/cumtime top + callers 定位 + 模块聚合 + 上次编译耗时)
This commit is contained in:
TermiNexus committed 2026-08-19 00:28:18 +08:00
1 parent bdc5ec3e88
commit 1808e90fd3
3 files changed
+205 -1

No files matched your search

+12
View File
@@ -147,10 +147,17 @@ def main() -> None:
parser.add_argument('--run', action='store_true', help='编译成功后立即执行生成的可执行文件')
parser.add_argument('--rebuild-includes', action='store_true', help='删除 includes.binary 预编译缓存并重新编译所有 includes')
parser.add_argument('--clear-cache', action='store_true', help='清除 .transpyc_cache 全局缓存(.vpi/.stub.ll/.doc.json)')
parser.add_argument('--asan', action='store_true', help='ASan 模式:对全部 .ll 做 opt -passes=asan 插桩并链接 -fsanitize=address(需 clang64 环境)')
parser.add_argument('--nowarn-register', action='store_true', help='抑制"外部函数返回类型未登记"类 WARN 输出(透传给自举编译的 TransPyV.exe)')
args: argparse.Namespace = parser.parse_args()
# ASan 模式(--asan):透传 TPC_ASAN=1 供 Phase2Translator 及 worker 子进程
# 检测(compile_ll_to_obj 先 opt -passes=asan 插桩,链接追加 -fsanitize=address)。
if args.asan:
os.environ['TPC_ASAN'] = '1'
_vlog().info('ASan 模式已启用(opt -passes=asan + -fsanitize=address)', 'asan')
project_file: str | None = args.project
if not project_file:
candidates: list[str] = ['project.json', './project.json']
@@ -196,6 +203,11 @@ def main() -> None:
if target_datalayout:
_vlog().info(f"数据布局: {target_datalayout}")
# 每次编译自动清理子进程性能剖析输出(PROF 目录 *.prof,硬编码路径)
from lib.Projectrans.Phase2Translator import _CleanProfFiles, PROF_DIR
_CleanProfFiles()
_vlog().info(f"PROF 目录已清理: {PROF_DIR}")
if args.clean:
if output_dir and os.path.exists(output_dir):
for f in os.listdir(output_dir):