Merged
mstx data support combine multi data of same mark_id #346
mei-feiyaoAdd on Jul 8
mstx data support combine multi data of same mark_id #346
Merged
mei-feiyaoAdd on Jul 8
mei-feiyao
mei-feiyaoCollaborators
Jul 8

PR 合入模板

注:经过自检不涉及的可标注“不涉及”或直接打勾,特殊情况请文字备注。不符合规范的 PR 不允许合入,请(后备)commit 注意。


1. 修改描述

  • 修改原因:
    mstx打点用例报错,原因在于模型打点数据超过156字节,mstx模块校验报错
  • 修改内容:
    落盘阶段发现数据超过156字节,拆分成多条;解析阶段发现同一mark id的数据存在多条,按照设置的数据块序号拼接打点数据

2. 功能验证

  • 功能自验
    image.png
  • 本地自验用例截图
  • 冒烟是否通过 (填入群链接的自验证报告中,如未通过,请说明原因:____________________ ,功能代码请主动申报添加冒烟)

3. 分支合并要求

  • 代码合并(请确保将 master 分支的最新代码同步合并至 poc 分支及 pre-research 分支,同时保证 poc 分支的代码也已正确合并到 pre-research 分支。)

3. 代码检视

  • 要求:

    • 合入代码超过 200 行,需三人以上会议检视。
    • 检视密度≥1个/100行。
    • 检视缺陷密度未达要求需提供说明。
    • 大于 1000 行代码原则上不允许合入,需进行备案。
  • 是否经过代码检视

  • 是否具备 UT 测试用例看护 (如不符合,请说明原因:____________________)

  • 检视意见数:____ 条 (请填写本次检视的意见总数,用于commit合入前审视)


4. 安全自检

Python、C++

  • 对外接口新增/删除/变更后,资料要同步新增/删除/变更,新增接口入参校验参考外部输入表格
  • 不允许私有的文件操作,需要使用公共模块的安全函数
  • 任务结束后需要删除临时文件,同时需要考虑任务失败后,临时文件没有残留
  • 数组访问需要校验越界场景,对除法需要做除零校验
  • 需要对递归方法做递归深度校验,正则表达式必须做 ReDoS 校验
  • 需要充分进行接口输入和返回值异常情况的校验
  • 日志打印不要出现拼写或语法错误,不要暴露代码细节和敏感信息

C++

  • 指针使用前需要判空
  • 数值计算校验溢出和反转
  • 不可存在内存泄漏(异常场景需要释放内存)
  • 类型转换不能出现数据截断
  • 拷贝字符串时,目的缓冲区至少比源缓冲区大 1
  • 拷贝内存时,目的缓冲区不小于源缓冲区
  • 内存释放后指针赋值为 nullptr

5. 变更知会

  • 资料修改
  • 变更通知(消息知会 + 邮件知会)

likedislike
Pull Request has been successfully merged by ascend-robot.
(Thank you for mei-feiyao's contribution.)
atomgit-bot
atomgit-bot
Jul 8 Comments:

变更摘要

此 PR 主要解决 MSTX 打点数据超过 156 字节时模块校验报错的问题。落盘阶段会将超长数据拆分为多条片段(每条带有相同的 mark_id 和不同的 seg_idx),解析阶段则需要识别同一 mark_id 的多条数据,按 seg_idx 排序后拼接还原完整消息。核心改动涉及解析器内部数据结构从列表改为字典分组、save() 阶段增加合并逻辑,以及解码器新增 seg_idx 字段支持。

主要改动

  • MsprofTxParser 内部数据结构变更_msproftx_ex_datalist 改为 dict_msproftx_ex_data_dict),key 为 mark_id,value 为该 mark_id 对应的数据对象列表,用于支持同 mark_id 多片段的分组存储
  • _parse_data()mark_id 分组收集:在 TX_EX_INFO_TYPE 分支中,不再直接将数据追加到扁平列表,而是按 data_object.mark_id 分组存入 _msproftx_ex_data_dict
  • save() 增加多片段合并逻辑:遍历 _msproftx_ex_data_dict,对每个 mark_id 的片段按 seg_idx 排序、校验片段是否连续(缺失时输出 warning)、拼接所有片段的 message 字段为 full_msg,再写入数据库
  • MsprofTxDecoder 新增 seg_idx 属性:在 __init__ 中从 filed[7] 读取 _seg_idx,并暴露为只读属性,同时移除未使用的 Constant 导入
  • 单元测试适配新结构:测试用例中的断言从 _msproftx_ex_data 更新为 _msproftx_ex_data_dict,合并了重复的 test_save_with_msproftx_data 方法,并在 test_parse_should_run_success_when_open_file_success 中统一验证解析与保存流程
likedislike
atomgit-bot
atomgit-bot
Jul 8 Comments:

代码审查

审查总结

按优先级统计:

  • P2:2 个问题
    • 测试中 save() 未 mock DB 依赖,测试脆弱
    • 缺少多分段消息拼接的核心功能测试覆盖
  • P3:3 个问题
    • check.save() 被连续调用了两次,疑似遗留调试代码
    • hash_data_msproftx_ex_data_dict 为空时仍被计算(可选优化)
    • 未检测同一 mark_id 下的重复 seg_idx

已审查文件

文件 结果
analysis/msparser/msproftx/msproftx_parser.py 发现 2 个 P3 问题
analysis/profiling_bean/struct_info/msproftx_decoder.py 无问题
test/msprof_python/ut/testcase/msparser/msproftx/test_msproftx_parser.py 发现 2 个 P2 + 1 个 P3 问题

总体风险评估中等。核心逻辑(按 seg_idx 排序拼接多分段消息)正确,seg_idx 字段的 struct 布局与 decoder 一致。主要风险集中在测试层面——核心功能缺少多分段场景的测试覆盖,且测试对 DB 层的隔离被移除,降低了测试的健壮性。建议在合入前补充多分段数据的测试用例并恢复 DB mock。

类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:

CLA Signature Pass

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

likedislike
ascend-robot
ascend-robotCollaborators
Jul 8 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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-Ascend/msprof 陈豪, Seanesmhxocism (2/2) 陈豪 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
mei-feiyao
mei-feiyaoCollaborators
Jul 8 Comments:

compile

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Added label: ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Jul 8 Added label: docs-ci-pipeline-success
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Removed label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Jul 8 Added label: docs-ci-pipeline-running
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robotCollaborators
Jul 8 Removed label: docs-ci-pipeline-running
ascend-robotascend-robotCollaborators
Jul 8 Added label: docs-ci-pipeline-success
ascend-robotascend-robotCollaborators
Jul 8 Removed label: ci-pipeline-running
ascend-robotascend-robotCollaborators
Jul 8 Added label: ci-pipeline-passed
ascend-robot
ascend-robotCollaborators
Jul 8 Comments:
流水线 PR-pipeline_msprof#1184 [ commitID:25d02c1a ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_msprof_arm >>>
Build_msprof_x86 >>>
恶意代码检查 Antipoison_msprof >>>
编码安全与规范检查 CodeCheck_msprof >>>
PreCommit_gitcode >>>
开源片段检查 SCA_msprof >>>
开发者测试 UT_msprof >>>
PreSmoke_msprof >>>
流水线 PR-pipeline_msprof >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
atomgit-bot
atomgit-botJul 8Start code review1
test/msprof_python/ut/testcase/msparser/msproftx/test_msproftx_parser.py
@@ -71,7 +71,7 @@
7171 with FdOpen(os.path.join(cls.DATA_PATH, "aging.additional.msproftx.slice_0"), operate="wb") as f:
7272 for data in msproftx_data:
7373 bytes_data = struct.pack(StructFmt.MSPROFTX_FMT, *data)
7474 f.write(bytes_data)
atomgit-bot
atomgit-botJul 8Comments:

🟡 Medium Priority

本 PR 的核心功能是:当打点数据超过 156 字节时拆分为多条(不同 seg_idx),解析阶段按 seg_idx 排序后拼接。但测试数据 make_msproftx_data(第 63-74 行)仅构造了 seg_idx=0 的单条消息(155 个 's'),未覆盖多分段拼接场景。这意味着 save() 中的排序逻辑(obj_list.sort(key=lambda x: x.seg_idx))、连续性校验(missing_segs)、以及消息拼接("".join(...))均无测试验证,PR 所述的核心功能缺乏测试看护。

建议:在 make_msproftx_data 中增加多分段测试数据(同一 mark_id、不同的 seg_idx),并在测试中验证拼接后的 full_msg 内容正确、missing_segs 告警逻辑在缺段时能触发。

likedislike
atomgit-bot
atomgit-botJul 8Start code review1
test/msprof_python/ut/testcase/msparser/msproftx/test_msproftx_parser.py
@@ -108,4 +99,1 @@
108- InfoConfReader()._info_json = {"devices": '0'}
109- check = MsprofTxParser(self.file_list, self.CONFIG)
110- check._msproftx_ex_data = [123]
11199 check.save()
atomgit-bot
atomgit-botJul 8Comments:

🟡 Medium Priority

变更后的 test_parse_should_run_success_when_open_file_success(第 91-99 行)调用了 check.save(),但未 mock HashDictDataMsprofTxModelMsprofTxExModel。旧代码中原本有独立的 test_save_with_msproftx_data 测试方法,通过 mock MsprofTxModel.flushMsprofTxExModel.flush 来隔离 DB 操作。现在 save() 直接执行真实的 DB 写入逻辑,其行为依赖运行时文件系统状态(host/sqlite/ 目录是否存在、sqlite3 是否可用等),导致测试脆弱,可能因环境差异而失败。

建议:在 test_parse_should_run_success_when_open_file_success 中 mock HashDictDataMsprofTxModel.flushMsprofTxExModel.flush,保持测试对 DB 层的隔离。或者将 save 调用恢复为独立的、带 mock 的测试方法。

likedislike
mei-feiyaomei-feiyaoCollaborators
Jul 8 Resolved final issue
wangzixuanCollaborators
Jul 8 Comments:

/lgtm

likedislike
chenhao_1209Collaborators
Jul 9 Comments:

/approve

likedislike
ascend-robotascend-robotCollaborators
Jul 9 Added label: approvedlgtm
ascend-robotascend-robotCollaborators
Jul 9 Merged pull request
ascend-robot
ascend-robotCollaborators
Jul 9 Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike