add-memory-trace-tags
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese内存跟踪标签添加
Adding Memory Tracking Tags
自动在 developtools_profiler 和 third_party_musl 仓库中添加新的资源跟踪类型标签。
Automatically add new resource tracking type tags across the developtools_profiler and third_party_musl repositories.
概述
Overview
此 skill 自动跨两个仓库的多个文件添加内存跟踪标签,确保定义一致、协议更新和测试覆盖。
This skill automatically adds memory tracking tags to multiple files across two repositories, ensuring consistent definitions, protocol updates, and test coverage.
使用场景
Usage Scenarios
适用于以下情况:
- 添加新的资源跟踪类型(COMMON_* 或特定类型)
- 更新内存分析功能
- 扩展跟踪标签系统
Applicable in the following cases:
- Adding new resource tracking types (COMMON_* or specific types)
- Updating memory profiling functionality
- Extending the trace tag system
快速参考
Quick Reference
| 组件 | 修改文件数 | 主要变更 |
|---|---|---|
| third_party_musl | 2 个文件 | TAG 和 MASK 定义 |
| developtools_profiler | 9 个文件 | 协议、逻辑、测试 |
| Component | Number of Modified Files | Key Changes |
|---|---|---|
| third_party_musl | 2 files | TAG and MASK definitions |
| developtools_profiler | 9 files | Protocols, logic, tests |
使用方法
Usage Instructions
在对话中直接调用:
请添加一个新的资源跟踪标签 <标签名称>或
使用 add-res-trace-tag 添加 <标签名>Call directly in the conversation:
Please add a new resource tracking tag <tag name>Or
Use add-res-trace-tag to add <tag name>参数说明
Parameter Description
此 skill 会提示输入:
-
标签名称(必填)
- 格式:大写字母和下划线
- 风格:或描述性名称
COMMON_<类型名> - 示例:、
COMMON_PIXELMAPCREATE_NATIVE_WINDOW_FROM_SURFACE
-
描述(可选)
- 用途说明
-
是否绕过大小过滤(可选,默认:是)
- 通用资源类型通常需要绕过大小过滤
This skill will prompt for the following inputs:
-
Tag Name (Required)
- Format: Uppercase letters and underscores
- Style: or descriptive name
COMMON_<type name> - Examples: ,
COMMON_PIXELMAPCREATE_NATIVE_WINDOW_FROM_SURFACE
-
Description (Optional)
- Usage explanation
-
Bypass Size Filter? (Optional, Default: Yes)
- Common resource types typically need to bypass size filtering
修改内容
Modified Content
third_party_musl(2 个文件)
third_party_musl (2 files)
- - TAG、MASK、位域布局
src/hook/linux/memory_trace.h - - 重复定义
porting/linux/user/src/hook/memory_trace.h
- - TAG, MASK, bitfield layout
src/hook/linux/memory_trace.h - - Duplicate definitions
porting/linux/user/src/hook/memory_trace.h
developtools_profiler(9 个文件)
developtools_profiler (9 files)
协议:
- - TraceType、MemoryType 枚举
protos/types/plugins/native_hook/native_hook_result.proto
常量:
- - 索引常量
device/plugins/native_daemon/include/hook_common.h
业务逻辑:
- - TagId 映射
device/plugins/native_hook/src/hook_guard.cpp - - 掩码转换
device/plugins/native_daemon/src/hook_manager.cpp - - 统计映射
device/plugins/native_daemon/src/stack_preprocess.cpp - - TraceType 设置
device/plugins/native_daemon/src/hook_record.cpp - - 过滤条件(仅 COMMON_* 类型)
device/plugins/native_hook/src/hook_client.cpp
测试:
device/plugins/native_daemon/test/unittest/common/native/hook_record_test.cppdevice/plugins/native_daemon/test/unittest/common/native/stack_preprocess_test.cpp
Protocols:
- - TraceType and MemoryType enums
protos/types/plugins/native_hook/native_hook_result.proto
Constants:
- - Index constants
device/plugins/native_daemon/include/hook_common.h
Business Logic:
- - TagId mapping
device/plugins/native_hook/src/hook_guard.cpp - - Mask conversion
device/plugins/native_daemon/src/hook_manager.cpp - - Statistics mapping
device/plugins/native_daemon/src/stack_preprocess.cpp - - TraceType setting
device/plugins/native_daemon/src/hook_record.cpp - - Filter conditions (COMMON_* types only)
device/plugins/native_hook/src/hook_client.cpp
Tests:
device/plugins/native_daemon/test/unittest/common/native/hook_record_test.cppdevice/plugins/native_daemon/test/unittest/common/native/stack_preprocess_test.cpp
常见错误
Common Errors
MASK 定义规则
MASK Definition Rules
每个资源类型必须定义两个宏:
c
// ✅ 正确:同时定义两个宏
#define RES_COMMON_WINDOW (1ULL << 33)
#define RES_COMMON_WINDOW_MASK (1ULL << 33)
// ❌ 错误:缺少 _MASK 后缀
#define RES_COMMON_WINDOW (1ULL << 33)
// 缺少 RES_COMMON_WINDOW_MASK!为什么需要两个定义:
- - 基础掩码值
RES_<NAME> - - 统一接口的别名
RES_<NAME>_MASK
常见错误场景:
错误 1:忘记添加 _MASK 后缀
#define RES_COMMON_SURFACE (1ULL << 34) // ✅ 有这个
// ❌ 缺少:#define RES_COMMON_SURFACE_MASK (1ULL << 34)
错误 2:只复制了第一行
#define RES_COMMON_TEXTURE (1ULL << 35) // ✅ 有这个
#define RES_COMMON_TEXTURE // ❌ 这行是错的!应该是 (1ULL << 35)Skill 自动验证:
此 skill 会自动检查是否两个定义都存在,如果缺失会自动添加。
Each resource type must define two macros:
c
// ✅ Correct: Define both macros
#define RES_COMMON_WINDOW (1ULL << 33)
#define RES_COMMON_WINDOW_MASK (1ULL << 33)
// ❌ Error: Missing _MASK suffix
#define RES_COMMON_WINDOW (1ULL << 33)
// Missing RES_COMMON_WINDOW_MASK!Why two definitions are needed:
- - Base mask value
RES_<NAME> - - Alias for unified interface
RES_<NAME>_MASK
Common Error Scenarios:
Error 1: Forgot to add _MASK suffix
#define RES_COMMON_SURFACE (1ULL << 34) // ✅ Exists
// ❌ Missing: #define RES_COMMON_SURFACE_MASK (1ULL << 34)
Error 2: Only copied the first line
#define RES_COMMON_TEXTURE (1ULL << 35) // ✅ Exists
#define RES_COMMON_TEXTURE // ❌ This line is wrong! Should be (1ULL << 35)Skill Automatic Verification:
This skill will automatically check if both definitions exist, and add them automatically if missing.
验证清单
Verification Checklist
添加新标签后检查:
- musl 主文件:TAG 已定义
- musl 主文件:MASK 已定义(两个都要)
- musl porting 文件:TAG 已定义
- musl porting 文件:MASK 已定义(两个都要)
- proto:TraceType 枚举值已添加
- proto:MemoryType 枚举值已添加
- hook_common.h:索引已定义
- hook_common.h:RESTRACE_TYPE_COUNT 已更新
- hook_guard.cpp:映射已添加
- hook_manager.cpp:转换逻辑已添加
- stack_preprocess.cpp:SaveMemTag 和 AddAllocStatistics 已添加
- hook_record.cpp:SetTraceType 分支已添加
- hook_client.cpp:过滤条件已更新(仅 COMMON_* 类型)
- 测试:测试用例已添加
Check the following after adding a new tag:
- musl main file: TAG is defined
- musl main file: MASK is defined (both required)
- musl porting file: TAG is defined
- musl porting file: MASK is defined (both required)
- proto: TraceType enum value added
- proto: MemoryType enum value added
- hook_common.h: Index defined
- hook_common.h: RESTRACE_TYPE_COUNT updated
- hook_guard.cpp: Mapping added
- hook_manager.cpp: Conversion logic added
- stack_preprocess.cpp: SaveMemTag and AddAllocStatistics added
- hook_record.cpp: SetTraceType branch added
- hook_client.cpp: Filter conditions updated (COMMON_* types only)
- Tests: Test cases added
约束条件
Constraints
- 标签命名:大写字母和下划线
- 比特位分配:从 bit 34 开始(当前用到 bit 33)
- 索引分配:从 23 开始(当前最大索引 22)
- 枚举值:自动递增,不与现有值冲突
- 仓库路径:假设为
d:\Code\tools_develop\ - RESTRACE_TYPE_COUNT:必须等于最大索引 + 1
- Tag Naming: Uppercase letters and underscores only
- Bit Allocation: Start from bit 34 (bit 33 is currently in use)
- Index Allocation: Start from 23 (current maximum index is 22)
- Enum Values: Auto-increment, no conflicts with existing values
- Repository Path: Assumed to be
d:\Code\tools_develop\ - RESTRACE_TYPE_COUNT: Must equal maximum index + 1
注意事项
Notes
- 编译顺序:修改 musl 后需要重新编译,profiler 才能使用新宏定义
- 协议兼容性:protobuf 修改后需要重新生成 C++ 代码
- 测试覆盖:所有修改都会添加相应的测试用例
- COMMON_ 类型*:只有 COMMON_* 前缀的类型才需要更新 的过滤条件
hook_client.cpp
- Compilation Order: Recompile after modifying musl so the profiler can use the new macro definitions
- Protocol Compatibility: Regenerate C++ code after modifying protobuf
- Test Coverage: Corresponding test cases are added for all modifications
- COMMON_ Types*: Only types with the COMMON_* prefix require updating the filter conditions in
hook_client.cpp
错误处理
Error Handling
| 错误 | 解决方案 |
|---|---|
| 标签已存在 | 使用不同的标签名称 |
| 文件未找到 | 验证仓库路径 |
| 权限被拒绝 | 检查文件写入权限 |
| 格式无效 | 标签名称必须是大写字母和下划线 |
| 缺少 MASK | Skill 自动添加 RES_*_MASK 定义 |
| 定义不匹配 | RES_* 和 RES_*_MASK 的值必须相同 |
| Error | Solution |
|---|---|
| Tag already exists | Use a different tag name |
| File not found | Verify the repository path |
| Permission denied | Check file write permissions |
| Invalid format | Tag name must consist of uppercase letters and underscores |
| Missing MASK | Skill automatically adds the RES_*_MASK definition |
| Mismatched definitions | RES_* and RES_*_MASK must have the same value |