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_musl2 个文件TAG 和 MASK 定义
developtools_profiler9 个文件协议、逻辑、测试
ComponentNumber of Modified FilesKey Changes
third_party_musl2 filesTAG and MASK definitions
developtools_profiler9 filesProtocols, 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 会提示输入:
  1. 标签名称(必填)
    • 格式:大写字母和下划线
    • 风格:
      COMMON_<类型名>
      或描述性名称
    • 示例:
      COMMON_PIXELMAP
      CREATE_NATIVE_WINDOW_FROM_SURFACE
  2. 描述(可选)
    • 用途说明
  3. 是否绕过大小过滤(可选,默认:是)
    • 通用资源类型通常需要绕过大小过滤
This skill will prompt for the following inputs:
  1. Tag Name (Required)
    • Format: Uppercase letters and underscores
    • Style:
      COMMON_<type name>
      or descriptive name
    • Examples:
      COMMON_PIXELMAP
      ,
      CREATE_NATIVE_WINDOW_FROM_SURFACE
  2. Description (Optional)
    • Usage explanation
  3. 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)

  • src/hook/linux/memory_trace.h
    - TAG、MASK、位域布局
  • porting/linux/user/src/hook/memory_trace.h
    - 重复定义
  • src/hook/linux/memory_trace.h
    - TAG, MASK, bitfield layout
  • porting/linux/user/src/hook/memory_trace.h
    - Duplicate definitions

developtools_profiler(9 个文件)

developtools_profiler (9 files)

协议:
  • protos/types/plugins/native_hook/native_hook_result.proto
    - TraceType、MemoryType 枚举
常量:
  • device/plugins/native_daemon/include/hook_common.h
    - 索引常量
业务逻辑:
  • device/plugins/native_hook/src/hook_guard.cpp
    - TagId 映射
  • device/plugins/native_daemon/src/hook_manager.cpp
    - 掩码转换
  • device/plugins/native_daemon/src/stack_preprocess.cpp
    - 统计映射
  • device/plugins/native_daemon/src/hook_record.cpp
    - TraceType 设置
  • device/plugins/native_hook/src/hook_client.cpp
    - 过滤条件(仅 COMMON_* 类型)
测试:
  • device/plugins/native_daemon/test/unittest/common/native/hook_record_test.cpp
  • device/plugins/native_daemon/test/unittest/common/native/stack_preprocess_test.cpp
Protocols:
  • protos/types/plugins/native_hook/native_hook_result.proto
    - TraceType and MemoryType enums
Constants:
  • device/plugins/native_daemon/include/hook_common.h
    - Index constants
Business Logic:
  • device/plugins/native_hook/src/hook_guard.cpp
    - TagId mapping
  • device/plugins/native_daemon/src/hook_manager.cpp
    - Mask conversion
  • device/plugins/native_daemon/src/stack_preprocess.cpp
    - Statistics mapping
  • device/plugins/native_daemon/src/hook_record.cpp
    - TraceType setting
  • device/plugins/native_hook/src/hook_client.cpp
    - Filter conditions (COMMON_* types only)
Tests:
  • device/plugins/native_daemon/test/unittest/common/native/hook_record_test.cpp
  • device/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!
为什么需要两个定义:
  1. RES_<NAME>
    - 基础掩码值
  2. 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:
  1. RES_<NAME>
    - Base mask value
  2. RES_<NAME>_MASK
    - Alias for unified interface
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

  1. 编译顺序:修改 musl 后需要重新编译,profiler 才能使用新宏定义
  2. 协议兼容性:protobuf 修改后需要重新生成 C++ 代码
  3. 测试覆盖:所有修改都会添加相应的测试用例
  4. COMMON_ 类型*:只有 COMMON_* 前缀的类型才需要更新
    hook_client.cpp
    的过滤条件
  1. Compilation Order: Recompile after modifying musl so the profiler can use the new macro definitions
  2. Protocol Compatibility: Regenerate C++ code after modifying protobuf
  3. Test Coverage: Corresponding test cases are added for all modifications
  4. COMMON_ Types*: Only types with the COMMON_* prefix require updating the filter conditions in
    hook_client.cpp

错误处理

Error Handling

错误解决方案
标签已存在使用不同的标签名称
文件未找到验证仓库路径
权限被拒绝检查文件写入权限
格式无效标签名称必须是大写字母和下划线
缺少 MASKSkill 自动添加 RES_*_MASK 定义
定义不匹配RES_* 和 RES_*_MASK 的值必须相同
ErrorSolution
Tag already existsUse a different tag name
File not foundVerify the repository path
Permission deniedCheck file write permissions
Invalid formatTag name must consist of uppercase letters and underscores
Missing MASKSkill automatically adds the RES_*_MASK definition
Mismatched definitionsRES_* and RES_*_MASK must have the same value