feat(tpc): PROF 输出按编译启动时间分目录,不再清理旧目录
需求(2026-09-29):PROF 按启动时间分组新建文件夹生成,不清理旧的 PROF。
改动:
- Phase2Translator:新增 `StartProfRun()`(在 PROF 根目录下按 `YYYYmmdd_HHMMSS`
新建本次编译专属子目录,同名补 `_N`;失败回落 PROF 根目录)与
`GetProfRunDir()`(主进程用已选定目录,worker 用继承的环境变量
`TPC_PROF_RUN_DIR` 复用同一目录)。原 `_CleanProfFiles()` 删除——它的语义
是"每次编译删掉 PROF 下全部 *.prof",与"保留历次"直接冲突。
- worker_prof_*.prof 落 `PROF/<启动时间>/`。
- main_prof_{pid}.prof 与 main_time.txt 同样落该目录(Projectrans.py)。
- Config.main 启动时调用 StartProfRun 并打印本次输出目录。
子目录名经环境变量传子进程:ProcessPoolExecutor 用 spawn 起新解释器,进程内
模块态不共享,环境变量随进程继承 ⇒ 同一次编译的所有 worker 落在同一目录,
不会各建各的。
This commit is contained in:
1 parent
467e62a45e
commit
030d0fd149
3 files changed
+66
-26
No files matched your search
+7
-6
@@ -22,8 +22,8 @@ __all__ = [
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 主进程性能剖析:整次编译过程(Phase1 声明生成 + Phase2 翻译/编译/链接)
|
||||
# 自动导出 cProfile dump 到 ./PROF/main_prof_{pid}.prof(与 worker 子进程
|
||||
# worker_prof_*.prof 同目录,可用 PROF/1.py 合并分析)。主进程 profile 主要
|
||||
# 自动导出 cProfile dump 到 ./PROF/<启动时间>/main_prof_{pid}.prof(与 worker
|
||||
# 子进程 worker_prof_*.prof 同目录)。主进程 profile 主要
|
||||
# 覆盖 Phase1/依赖扫描/编译调度/链接等主进程侧耗时;worker 内部 CPU 分布
|
||||
# 仍由 _ProfileWorker 的 worker_prof_*.prof 覆盖(多进程下主进程 cProfile
|
||||
# 看不到子进程内部热点,两者互补)。
|
||||
@@ -31,7 +31,7 @@ if __name__ == '__main__':
|
||||
import os as _os
|
||||
import sys as _sys
|
||||
import time as _time
|
||||
from lib.Projectrans.Phase2Translator import PROF_DIR as _PROF_DIR
|
||||
from lib.Projectrans.Phase2Translator import GetProfRunDir as _GetProfRunDir
|
||||
|
||||
_main_prof: _cProfile.Profile = _cProfile.Profile()
|
||||
_main_prof.enable()
|
||||
@@ -48,9 +48,10 @@ if __name__ == '__main__':
|
||||
_timing_msg: str = f'[TIMING] 编译{_timing_status},总耗时 {_elapsed_s:.2f}s'
|
||||
print(_timing_msg, file=_sys.stderr)
|
||||
try:
|
||||
_os.makedirs(_PROF_DIR, exist_ok=True)
|
||||
_main_prof.dump_stats(_os.path.join(_PROF_DIR, f'main_prof_{_os.getpid()}.prof'))
|
||||
with open(_os.path.join(_PROF_DIR, 'main_time.txt'), 'w', encoding='utf-8') as _tf:
|
||||
_prof_dir: str = _GetProfRunDir()
|
||||
_os.makedirs(_prof_dir, exist_ok=True)
|
||||
_main_prof.dump_stats(_os.path.join(_prof_dir, f'main_prof_{_os.getpid()}.prof'))
|
||||
with open(_os.path.join(_prof_dir, 'main_time.txt'), 'w', encoding='utf-8') as _tf:
|
||||
_tf.write(f'{_timing_status}\t{_elapsed_s:.2f}\n')
|
||||
except Exception:
|
||||
pass
|
||||
Reference in new issue
Block a user