Pull Request已成功合入, 合并人@ascend-robot
(感谢 xieanran 的贡献)变更摘要
该 PR 主要适配 prof level 0 场景下仅包含 task track shapes(运行时算子,如 aclgraph)的落盘逻辑。核心改动是:AddTensorShapeInfo 的入参由按值传递的 MsprofNodeBasicInfo 改为可空的指针 const MsprofNodeBasicInfo * 并移除 isLevel0 分支,当没有节点基本信息时算子名回退为 task->op->name,其余节点级字段(opState、taskType、opType、opFlag、hashId 等)回退为 NA/0;同时在 C++ 侧 AddTaskInfoForOnlyTaskTrack 与 Python 侧 TaskGear 中,当运行时算子信息有效且 tensorNum > 0 时,将 tensor 信息(tensor 数量、输入/输出 format、数据类型、shape)实际写入落盘数据,而非固定写 0/NA/None。
主要改动
AddTensorShapeInfo接口重构: 参数由值传递的MsprofNodeBasicInfo改为可空指针const MsprofNodeBasicInfo *nodeBasicInfo,删除isLevel0参数,通过hasNodeBasicInfo统一两种场景;无节点信息时opName取task->op->name,opState/taskType/opType/opFlag/hashId回退为NA,blockNum/mixBlockNum回退为 0。- level 0 仅 task track 场景支持 tensor 信息落盘:
AddTaskInfoForOnlyTaskTrack中当info.isValid && info.tensorNum > 0时写入info.tensorNum及输入/输出inputFormats、inputDataTypes、inputShapes、outputFormats、outputDataTypes、outputShapes,否则保持 0/NA;AddTaskInfo的 level 0 分支增加desc->tensorDesc->tensorNum > 0校验后再调用AddTensorShapeInfo(desc->tensorDesc, nullptr, data, task)。 - Python 侧
TaskGear同步适配:cann_analysis_gear.py中新增has_tensor_info判断(tensor_num非空且大于 0,level 0 分支额外要求op_info.is_valid),满足条件时输出真实的 tensor 信息,否则对应字段为None。 - 补充单元测试: C++ UT 新增
TestAddTaskInfoWhenTypeIsReservedAndProfLevel0WithTensorInfo,Python UT 新增test_task_gear_should_save_runtime_tensor_info_for_aclgraph_in_prof_level0,分别验证 prof level 0 下保留算子(aclgraph_op)的 tensor 数量、输入输出 shape 等信息可正确保存。


代码审查
All changed files have been reviewed and the confirmed findings reported. I have completed my investigation within budget.
审查结论
按文件确认
- analysis/csrc/domain/services/persistence/host/cann_trace_db_dumper.cpp — 已审查。
AddTensorShapeInfo改为可空指针参数、两个调用点均同步更新,level0 路径语义与原isLevel0=true分支一致(NA/0 回退),无边界问题。问题:新增的hasTensorInfo = info.isValid && info.tensorNum > 0(line 383)依赖一个在生产加载链路上恒为 false 的标志,导致 level0 仅 task track 场景的 tensor 落盘新功能不可达(P2)。 - analysis/csrc/domain/services/persistence/host/cann_trace_db_dumper.h — 已审查。
AddTensorShapeInfo签名变更与 .cpp 实现及两处调用点(含测试)完全一致,无遗漏调用者,无问题。 - analysis/mscalculate/cann/cann_analysis_gear.py — 已审查。
add_kernel_task_l0门控基于tensor_num本身、不依赖 is_valid,逻辑正确;add_kernel_task_only_task_track的has_tensor_info门控与 C++ 侧存在同一 is_valid 恒 false 问题(与 finding 2 同根因,未重复上报)。 - test/msprof_cpp/analysis_ut/viewer/test/cann_db_dumper_utest.cpp — 已审查。问题:新测试
TestAddTaskInfoWhenTypeIsReservedAndProfLevel0WithTensorInfo(line 445)用 19 参构造函数构造RuntimeOpInfo,该构造函数不初始化isValid(默认 false),导致hasTensorInfo为 false、三条断言必然失败(P2)。 - test/msprof_python/ut/testcase/mscalculate/cann/test_cann_analysis_gear.py — 已审查。测试正确设置
is_valid=True,RTAddInfoCenter为单例(@singleton),实例级 patch 可命中add_kernel_task_only_task_track内的调用,断言位置 13:20 与落库顺序一致,无问题。
总体风险判断
共 2 条 P2 发现(无 P0/P1):
- 新增 C++ 单测必然失败(置信 0.85)——
RuntimeOpInfo19 参构造函数不置位isValid,测试走不进 level0 tensor 落盘分支,三条断言全红。 - 新功能在生产环境不可达(置信 0.65)——C++
RTAddInfoCenter::LoadDB与 PythonRuntimeOpInfoViewModel的加载链路从不把isValid/is_valid置为 true,PR 核心目标(level0 + task track shapes only 场景落盘 runtime tensor 信息)在真实数据上永远不会写 tensor 字段,功能形同死代码。
两者同根因(isValid 语义在数据加载链路缺失),建议一并修复:在加载处置位 isValid,或改用记录存在性(tensor_num 非空)作为门控。本次改动主体逻辑(指针化参数、NA 回退、两语言一致性)本身无正确性问题,但核心功能未真正生效且新增测试为红,合入前需修复。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/msprof | ✅ 潘杨杰, 陈豪 (2/2) | ✅ 潘杨杰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
SoraAzzz, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


PR 合入模板
注:经过自检不涉及的可标注“不涉及”或直接打勾,特殊情况请文字备注。不符合规范的 PR 不允许合入,请(后备)commit 注意。
1. 修改描述
2. 功能验证
3. 分支合并要求
3. 代码检视
要求:
检视意见数:__2 条 (请填写本次检视的意见总数,用于commit合入前审视)
4. 安全自检
Python、C++
C++
5. 变更知会