Merged
fix(dfx): keep log time initialization dependency out of error header #6560
fix(dfx): keep log time initialization dependency out of error header #6560
Merged
W4termyAdd on Sep 21
W4termy
W4termyCollaborators
Sep 21

性能用例批跑时,若线程在 libc 时间转换过程中持有 tzset_lock,此时被信号打断,TerminateHandler 回调打印日志会再次通过 std::localtime() 申请同一把锁,导致线程自我死锁。
修改内容

  • 新增私有 log_time.h/.cpp,迁移 dlog 的整数日历换算算法。
  • 在启动阶段初始化时区和夏令时配置,并在注册异常处理回调前显式确保初始化完成。
  • 日志时间和文件名时间共用换算路径,运行期间不再调用 localtime/localtime_r/tzset。
  • 保持原有日志格式、三位毫秒精度及文件名格式不变。
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for W4termy's contribution.)
W4termyW4termyCollaborators
Sep 21 Created pull request, commit f23dbcda
W4termyW4termyCollaborators
Sep 21 Associated issue: [Bug-Report|缺陷反馈]: 日志管理使用localtime(),重入调用导致死锁
atomgit-bot
atomgit-bot
Sep 21 Comments:

变更摘要

本次变更将日志时间相关功能从 error.h 与 log_manager.cpp 中解耦,抽离为独立的 log_time 模块。核心是把 TerminateHandler 的构造函数从 error.h 头文件内联定义移到 error.cpp 中实现,从而让错误头文件不再隐式依赖日志时间初始化逻辑;同时把原本位于 log_manager.cpp 的 GetCurrentTime、GetCurrentTimeStr 迁移到新增的 framework/src/utils/host_log/log_time.cpp,并新增显式的 InitializeLogTime() 初始化入口,配套增加了单元测试。

主要改动

  • TerminateHandler 构造函数外移: 将 framework/src/interface/utils/error.h 中 TerminateHandler 的内联构造函数改为仅声明,实现在 error.cpp 中完成,避免错误头文件携带日志时间初始化依赖。
  • 新增显式初始化入口 InitializeLogTime(): 在 error.cpp 的 TerminateHandler 构造函数安装信号处理器与 set_terminate 之前调用 InitializeLogTime(),确保处理回调可安全记录日志。
  • 抽离时间模块: 新增 framework/src/utils/host_log/log_time.cpp 与 log_time.h,提供 InitializeLogTime()、GetCurrentTime()、GetCurrentTimeStr() 三个接口,并从 log_manager.cpp 删除原有同名时间函数、改为包含新头文件。
  • 时间实现调整: 新模块使用 std::call_once 加 std::once_flag 保证初始化仅执行一次,通过 gettimeofday、tzset、localtime_r 获取时区与 DST,并自行计算本地时间,GetCurrentTimeStr 由 GetCurrentTime 去除分隔符生成。
  • 新增单元测试: 增加 framework/tests/ut/machine/src/utils/test_log_time.cpp,覆盖本地时间戳格式、文件名时间戳格式及多线程并发生成的校验。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 21 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 21 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Sep 21 Added label: cann-cla/yes
W4termy
W4termyCollaborators
Sep 21 Comments:

compile

likedislike
W4termyW4termyCollaborators
Sep 21 Pre merge succeeded (commit_id: 7f53c92c47de5eb10c99be2c6a616b12c747fb48)
CANN-robot
CANN-robotCollaborators
Sep 21 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
9.2.0 ✅ gcw_kUomxQ2l, gaoxingwang (2/2) ✅ gcw_kUomxQ2l (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

W4termy, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Sep 21 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robot
CANN-robotCollaborators
Sep 21 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 21 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 21 Added label: ci-pipeline-passed
W4termyW4termyCollaborators
Sep 21 Modify description of pull request
liulun0308
liulun0308Collaborators
Sep 21 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Added label: approved
gaoxingwang
gaoxingwangCollaborators
Sep 22 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 22 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 22 Merged pull request