Automatically add new resource tracking type tags in the developtools_profiler and third_party_musl repositories.
Overview
This skill automatically adds memory tracking tags across multiple files in two repositories, ensuring consistent definitions, protocol updates, and test coverage.
Use Cases
Applicable in the following situations:
- Adding a new resource tracking type (COMMON_* or a specific type)
- Updating memory analysis functionality
- Extending the tracking tag system
Quick Reference
| Component | Number of Files Modified | Main Changes |
|---|---|---|
| third_party_musl | 2 files | TAG and MASK definitions |
| developtools_profiler | 9 files | Protocol, logic, tests |
Usage
Call directly in the conversation:
请添加一个新的资源跟踪标签 <标签名称>
or
使用 add-res-trace-tag 添加 <标签名>
Parameter Description
This skill will prompt for input:
-
Tag name(required)
- Format: uppercase letters and underscores
- Style:
COMMON_<类型名>or a descriptive name - Example:
COMMON_PIXELMAP、CREATE_NATIVE_WINDOW_FROM_SURFACE
-
Description(optional)
- Purpose description
-
Whether to bypass size filtering(optional, default: yes)
- Common resource types usually need to bypass size filtering
Modification Details
third_party_musl (2 files)
src/hook/linux/memory_trace.h- TAG, MASK, bitfield layoutporting/linux/user/src/hook/memory_trace.h- Duplicate definition
developtools_profiler (9 files)
Protocol:
protos/types/plugins/native_hook/native_hook_result.proto- TraceType, MemoryType enums
Constants:
device/plugins/native_daemon/include/hook_common.h- Index constants
Business logic:
device/plugins/native_hook/src/hook_guard.cpp- TagId mappingdevice/plugins/native_daemon/src/hook_manager.cpp- Mask conversiondevice/plugins/native_daemon/src/stack_preprocess.cpp- Statistics mappingdevice/plugins/native_daemon/src/hook_record.cpp- TraceType settingdevice/plugins/native_hook/src/hook_client.cpp- Filter conditions (COMMON_* types only)
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 Definition Rules
Each resource type must define two macros:
// ✅ 正确:同时定义两个宏
#define RES_COMMON_WINDOW (1ULL << 33)
#define RES_COMMON_WINDOW_MASK (1ULL << 33)
// ❌ 错误:缺少 _MASK 后缀
#define RES_COMMON_WINDOW (1ULL << 33)
// 缺少 RES_COMMON_WINDOW_MASK!
Why two definitions are needed:
RES_<NAME>- Base mask valueRES_<NAME>_MASK- Alias for the unified interface
Common error scenarios:
错误 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 automatic verification: This skill will automatically check whether both definitions exist, and will automatically add them if missing.
Verification Checklist
After adding a new tag, check:
- musl main file: TAG is defined
- musl main file: MASK is defined (both are required)
- musl porting file: TAG is defined
- musl porting file: MASK is defined (both are required)
- proto: TraceType enum value is added
- proto: MemoryType enum value is added
- hook_common.h: index is defined
- hook_common.h: RESTRACE_TYPE_COUNT is updated
- hook_guard.cpp: mapping is added
- hook_manager.cpp: conversion logic is added
- stack_preprocess.cpp: SaveMemTag and AddAllocStatistics are added
- hook_record.cpp: SetTraceType branch is added
- hook_client.cpp: Filter conditions updated (only COMMON_* types)
- Test: Test cases added
Constraints
- Tag naming: Uppercase letters and underscores
- Bit allocation: Starts from bit 34 (currently bit 33 is used)
- Index allocation: Starts from 23 (currently the maximum index is 22)
- Enum values: Automatically incremented, does not conflict with existing values
- Repository path: Assumed to be
d:\Code\tools_develop\ - RESTRACE_TYPE_COUNT: Must equal the maximum index + 1
Notes
- Compilation order: After modifying musl, recompilation is required for the profiler to use the new macro definitions
- Protocol compatibility: After modifying protobuf, the C++ code needs to be regenerated
- Test coverage: Corresponding test cases will be added for all modifications
- COMMON_ types*: Only types with the COMMON_* prefix need to update the
hook_client.cppfilter conditions
Error handling
| 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 names must be uppercase letters and underscores |
| Missing MASK | Skill automatically adds the RES_*_MASK definition |
| Definition mismatch | The values of RES_* and RES_*_MASK must be the same |