* Copyright (C) 2025-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SelectionParam } from "./BoxSelection";
export enum MemoryTraceRowType {
ROW_TYPE_NATIVE_MEMORY = 'nativeMemory',
ROW_TYPE_GPU_MEMORY = 'gpuMemory',
ROW_TYPE_OTHER_SOURCE = 'otherSource'
}
export class MemoryTableName {
static readonly NATIVE_HOOK = 'native_hook';
static readonly NATIVE_HOOK_STATISTIC = 'native_hook_statistic';
}
export enum MemoryStatisticType {
MALLOC = 0,
MMAP = 1,
FILE_PAGE_MSG = 2,
MEMORY_USING_MSG = 3,
FD = 4,
THREAD = 5,
GPU_VK = 6,
GPU_GLES = 7,
GPU_CL = 8,
SO = 9,
ARKTS = 10,
JS = 11,
KMP = 12,
RN = 13,
ASHMEM = 14,
DMA = 15,
OTHER = 16,
ARK_GLOBAL_HANDLE = 17,
ARK_LOCAL_HANDLE = 18,
DART_HEAP = 20,
ARKTS_STATIC_HEAP = 21,
};
export class MemoryType {
static readonly MEMORY_M_ALLOC_NAME = 'AllocEvent';
static readonly MEMORY_M_MAP_NAME = 'MmapEvent';
static readonly MEMORY_M_FILE_PAGE_MSG = 'FILE_PAGE_MSG';
static readonly MEMORY_M_MEMORY_USING_MSG = 'MEMORY_USING_MSG';
static readonly MEMORY_M_FREE_NAME = 'FreeEvent';
static readonly MEMORY_M_UNMAP_NAME = 'MunmapEvent';
static readonly FD_OPEN_NAME = 'FD_Open_Event';
static readonly FD_SIMPLE_NAME = 'FD';
static readonly THREAD_CREATE_NAME = 'Thread_Create_Event';
static readonly THREAD_SIMPLE_NAME = 'Thread';
static readonly FD_CLOSE_NAME = 'FD_Close_Event';
static readonly THREAD_DESTROY_NAME = 'Thread_Destroy_Event';
static readonly GPU_CL_Alloc_NAME = 'GPU_CL_Alloc_Event';
static readonly GPU_CL_SIMPLE_NAME = 'GPU_CL';
static readonly GPU_CL_Free_NAME = 'GPU_CL_Free_Event';
static readonly GPU_GLES_Alloc_NAME = 'GPU_GLES_Alloc_Event';
static readonly GPU_GLES_SIMPLE_NAME = 'GPU_GLES';
static readonly GPU_GLES_Free_NAME = 'GPU_GLES_Free_Event';
static readonly GPU_VK_Alloc_NAME = 'GPU_VK_Alloc_Event';
static readonly GPU_VK_SIMPLE_NAME = 'GPU_VK';
static readonly GPU_VK_Free_NAME = 'GPU_VK_Free_Event';
static readonly ARKTS_Alloc_NAME = 'ARKTS_HEAP_Alloc_Event';
static readonly ARKTS_Free_NAME = 'ARKTS_HEAP_Free_Event';
static readonly JS_Alloc_NAME = 'JS_HEAP_Alloc_Event';
static readonly JS_Free_NAME = 'JS_HEAP_Free_Event';
static readonly KMP_Alloc_NAME = 'KMP_HEAP_Alloc_Event';
static readonly KMP_Free_NAME = 'KMP_HEAP_Free_Event';
static readonly ION_Alloc_NAME = 'ION_Alloc_Event';
static readonly ION_Free_NAME = 'ION_Free_Event';
static readonly SO_Alloc_NAME = 'SO_Alloc_Event';
static readonly SO_Free_NAME = 'SO_Free_Event';
static readonly ASHMEM_Alloc_NAME = 'ASHMEM_Alloc_Event';
static readonly ASHMEM_Free_NAME = 'ASHMEM_Free_Event';
static readonly DART_HEAP_Alloc_NAME = 'DART_HEAP_Alloc_Event';
static readonly DART_HEAP_Free_NAME = 'DART_HEAP_Free_Event';
static readonly ARKTS_STATIC_HEAP_Alloc_NAME = 'ARKTS_STATIC_HEAP_Alloc_Event';
static readonly ARKTS_STATIC_HEAP_Free_NAME = 'ARKTS_STATIC_HEAP_Free_Event';
static readonly RN_HERMES_HEAP_Alloc_NAME = 'RN_HERMES_HEAP_Alloc_Event';
static readonly RN_HERMES_HEAP_Free_NAME = 'RN_HERMES_HEAP_Free_Event';
static readonly ARK_GLOBAL_HANDLE_Alloc_NAME = 'ARK_GLOBAL_HANDLE_Alloc_Event';
static readonly ARK_GLOBAL_HANDLE_Free_NAME = 'ARK_GLOBAL_HANDLE_Free_Event';
static readonly ARK_LOCAL_HANDLE_Alloc_NAME = 'ARK_LOCAL_HANDLE_Alloc_Event';
static readonly ARK_LOCAL_HANDLE_Free_NAME = 'ARK_LOCAL_HANDLE_Free_Event';
static readonly APPLY_EVENTS = [MemoryType.MEMORY_M_ALLOC_NAME, MemoryType.MEMORY_M_MAP_NAME,
MemoryType.FD_OPEN_NAME, MemoryType.THREAD_CREATE_NAME,
MemoryType.GPU_VK_Alloc_NAME, MemoryType.GPU_GLES_Alloc_NAME, MemoryType.GPU_CL_Alloc_NAME,
MemoryType.ARKTS_Alloc_NAME, MemoryType.JS_Alloc_NAME,
MemoryType.KMP_Alloc_NAME, MemoryType.SO_Alloc_NAME, MemoryType.ASHMEM_Alloc_NAME,
MemoryType.ION_Alloc_NAME, MemoryType.DART_HEAP_Alloc_NAME, MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME, MemoryType.RN_HERMES_HEAP_Alloc_NAME, MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME, MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME];
static readonly APPLY_NM_EVENTS = [MemoryType.MEMORY_M_ALLOC_NAME, MemoryType.MEMORY_M_MAP_NAME,
MemoryType.ARKTS_Alloc_NAME, MemoryType.JS_Alloc_NAME, MemoryType.KMP_Alloc_NAME, MemoryType.ION_Alloc_NAME, MemoryType.SO_Alloc_NAME, MemoryType.ASHMEM_Alloc_NAME, MemoryType.DART_HEAP_Alloc_NAME, MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME, MemoryType.RN_HERMES_HEAP_Alloc_NAME, MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME, MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME];
static readonly ALL_HEAP_EVENTS = [MemoryType.MEMORY_M_ALLOC_NAME, MemoryType.ARKTS_Alloc_NAME, MemoryType.JS_Alloc_NAME, MemoryType.KMP_Alloc_NAME, MemoryType.DART_HEAP_Alloc_NAME, MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME, MemoryType.RN_HERMES_HEAP_Alloc_NAME, MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME, MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME];
static readonly ALL_ANONYMOUS_EVENTS = [MemoryType.MEMORY_M_MAP_NAME, MemoryType.ION_Alloc_NAME, MemoryType.SO_Alloc_NAME, MemoryType.ASHMEM_Alloc_NAME];
};
export const MemoryBasicType = {
NATIVE_MEMORY: [
'All Heap & Anonymous VM',
'All Heap',
'Native Heap',
'ArkTs Heap',
'JS Heap',
'Dart Heap',
'Arkts Static Heap',
'RN Heap',
'KMP Heap',
'All Anonymous VM',
'VM ION',
'VM Ashmem',
'VM SO',
'VM Others',
] as const,
GPU_MEMORY: [
'All Gpu Memory',
'Gpu VK',
'Gpu GLES',
'Gpu CL',
] as const,
OTHER_SOURCE: [
'All Other Source',
'FD',
'Thread',
] as const,
};
export const NATIVE_MEMORY_ALL_HEAP_IDX = 1;
export const NATIVE_MEMORY_HEAP_INDICES = [2, 3, 4, 5, 6, 7, 8] as const;
export const NATIVE_MEMORY_ALL_ANONYMOUS_VM_IDX = 9;
export const NATIVE_MEMORY_ANONYMOUS_VM_INDICES = [10, 11, 12, 13] as const;
export const nativeMemoryGroupConfig = {
allHeap: {
folderSuffix: NATIVE_MEMORY_ALL_HEAP_IDX,
childIndices: NATIVE_MEMORY_HEAP_INDICES,
},
allAnonymousVM: {
folderSuffix: NATIVE_MEMORY_ALL_ANONYMOUS_VM_IDX,
childIndices: NATIVE_MEMORY_ANONYMOUS_VM_INDICES,
}
};
export const memoryConfig: Record<
MemoryTraceRowType,
{
filters: Array<MemoryType>;
chartConfigs: Array<{ filter?: MemoryType | MemoryType[]; suffix: number; }>;
}
> = {
[MemoryTraceRowType.ROW_TYPE_NATIVE_MEMORY]: {
filters: [
MemoryType.MEMORY_M_ALLOC_NAME, MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME, MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME,
MemoryType.MEMORY_M_MAP_NAME, MemoryType.ARKTS_Alloc_NAME,
MemoryType.JS_Alloc_NAME, MemoryType.KMP_Alloc_NAME,
MemoryType.SO_Alloc_NAME, MemoryType.ASHMEM_Alloc_NAME,
MemoryType.ION_Alloc_NAME, MemoryType.DART_HEAP_Alloc_NAME, MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME, MemoryType.RN_HERMES_HEAP_Alloc_NAME
],
chartConfigs: [
{ suffix: 0 },
{ filter: [MemoryType.MEMORY_M_ALLOC_NAME, MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME, MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME], suffix: 2 },
{ filter: MemoryType.ARKTS_Alloc_NAME, suffix: 3 },
{ filter: MemoryType.JS_Alloc_NAME, suffix: 4 },
{ filter: MemoryType.DART_HEAP_Alloc_NAME, suffix: 5 },
{ filter: MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME, suffix: 6 },
{ filter: MemoryType.RN_HERMES_HEAP_Alloc_NAME, suffix: 7 },
{ filter: MemoryType.KMP_Alloc_NAME, suffix: 8 },
{ filter: MemoryType.ION_Alloc_NAME, suffix: 10 },
{ filter: MemoryType.ASHMEM_Alloc_NAME, suffix: 11 },
{ filter: MemoryType.SO_Alloc_NAME, suffix: 12 },
{ filter: MemoryType.MEMORY_M_MAP_NAME, suffix: 13 },
],
},
[MemoryTraceRowType.ROW_TYPE_OTHER_SOURCE]: {
filters: [MemoryType.FD_OPEN_NAME, MemoryType.THREAD_CREATE_NAME],
chartConfigs: [
{ filter: MemoryType.FD_OPEN_NAME, suffix: 0 },
{ filter: MemoryType.THREAD_CREATE_NAME, suffix: 1 },
],
},
[MemoryTraceRowType.ROW_TYPE_GPU_MEMORY]: {
filters: [MemoryType.GPU_VK_Alloc_NAME, MemoryType.GPU_GLES_Alloc_NAME, MemoryType.GPU_CL_Alloc_NAME],
chartConfigs: [
{ suffix: 0 },
{ filter: MemoryType.GPU_VK_Alloc_NAME, suffix: 1 },
{ filter: MemoryType.GPU_GLES_Alloc_NAME, suffix: 2 },
{ filter: MemoryType.GPU_CL_Alloc_NAME, suffix: 3 },
],
},
};
export const statisticTypeMap: Record<number, string> = {
0: "alloc",
1: "mmap",
2: "mmap",
3: "mmap",
4: "fd",
5: "thread",
6: "gpuVk",
7: "gpuGles",
8: "gpuCl",
9: "so",
10: "arkts",
11: "js",
12: "kmp",
13: "rn",
14: "ashmem",
15: "ion",
16: "other",
17: "arkGlobalHandle",
18: "arkLocalHandle",
20: "dartHeap",
21: "arktsStaticHeap",
};
type HandlerItem = {
rowType: MemoryTraceRowType;
suffixes: Array<{ key: string; suffix: string; }>;
sum?: true | string[];
};
export const handlerConfig: HandlerItem[] = [
{
rowType: MemoryTraceRowType.ROW_TYPE_NATIVE_MEMORY,
suffixes: [
{ key: "alloc", suffix: "2" },
{ key: "arkGlobalHandle", suffix: "2" },
{ key: "arkLocalHandle", suffix: "2" },
{ key: "arkts", suffix: "3" },
{ key: "js", suffix: "4" },
{ key: "dartHeap", suffix: "5" },
{ key: "arktsStaticHeap", suffix: "6" },
{ key: "rn", suffix: "7" },
{ key: "kmp", suffix: "8" },
{ key: "ion", suffix: "10" },
{ key: "ashmem", suffix: "11" },
{ key: "so", suffix: "12" },
{ key: "mmap", suffix: "13" },
],
sum: true,
},
{
rowType: MemoryTraceRowType.ROW_TYPE_OTHER_SOURCE,
suffixes: [
{ key: "fd", suffix: "0" },
{ key: "thread", suffix: "1" },
],
},
{
rowType: MemoryTraceRowType.ROW_TYPE_GPU_MEMORY,
suffixes: [
{ key: "gpuVk", suffix: "1" },
{ key: "gpuGles", suffix: "2" },
{ key: "gpuCl", suffix: "3" },
],
sum: true,
},
];
function mapTypeToFilters(type: string, isStat: boolean, needFree: boolean): Array<string | number> {
switch (type) {
case MemoryBasicType.NATIVE_MEMORY[0]:
return isStat
? [
MemoryStatisticType.MALLOC, MemoryStatisticType.MMAP,
MemoryStatisticType.FILE_PAGE_MSG, MemoryStatisticType.MEMORY_USING_MSG,
MemoryStatisticType.ARKTS, MemoryStatisticType.JS, MemoryStatisticType.KMP,
MemoryStatisticType.SO, MemoryStatisticType.ASHMEM, MemoryStatisticType.DMA,
MemoryStatisticType.DART_HEAP, MemoryStatisticType.ARKTS_STATIC_HEAP, MemoryStatisticType.RN, MemoryStatisticType.ARK_GLOBAL_HANDLE, MemoryStatisticType.ARK_LOCAL_HANDLE
]
: needFree
? [
`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.MEMORY_M_FREE_NAME}`,
`${MemoryType.MEMORY_M_MAP_NAME}`, `${MemoryType.MEMORY_M_UNMAP_NAME}`,
`${MemoryType.ARKTS_Alloc_NAME}`, `${MemoryType.ARKTS_Free_NAME}`,
`${MemoryType.JS_Alloc_NAME}`, `${MemoryType.JS_Free_NAME}`,
`${MemoryType.DART_HEAP_Alloc_NAME}`, `${MemoryType.DART_HEAP_Free_NAME}`,
`${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`, `${MemoryType.ARKTS_STATIC_HEAP_Free_NAME}`,
`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`, `${MemoryType.RN_HERMES_HEAP_Free_NAME}`,
`${MemoryType.KMP_Alloc_NAME}`, `${MemoryType.KMP_Free_NAME}`,
`${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Free_NAME}`,
`${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Free_NAME}`,
`${MemoryType.SO_Alloc_NAME}`, `${MemoryType.SO_Free_NAME}`,
`${MemoryType.ASHMEM_Alloc_NAME}`, `${MemoryType.ASHMEM_Free_NAME}`,
`${MemoryType.ION_Alloc_NAME}`, `${MemoryType.ION_Free_NAME}`
]
: [
`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.MEMORY_M_MAP_NAME}`,
`${MemoryType.ARKTS_Alloc_NAME}`, `${MemoryType.JS_Alloc_NAME}`,
`${MemoryType.DART_HEAP_Alloc_NAME}`, `${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`,
`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`, `${MemoryType.SO_Alloc_NAME}`,
`${MemoryType.ASHMEM_Alloc_NAME}`, `${MemoryType.ION_Alloc_NAME}`,
`${MemoryType.KMP_Alloc_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`
];
case MemoryBasicType.NATIVE_MEMORY[1]:
return isStat
? [MemoryStatisticType.MALLOC, MemoryStatisticType.ARKTS, MemoryStatisticType.JS,
MemoryStatisticType.DART_HEAP, MemoryStatisticType.ARKTS_STATIC_HEAP, MemoryStatisticType.RN, MemoryStatisticType.KMP, MemoryStatisticType.ARK_GLOBAL_HANDLE, MemoryStatisticType.ARK_LOCAL_HANDLE]
: needFree
? [
`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.MEMORY_M_FREE_NAME}`,
`${MemoryType.ARKTS_Alloc_NAME}`, `${MemoryType.ARKTS_Free_NAME}`,
`${MemoryType.JS_Alloc_NAME}`, `${MemoryType.JS_Free_NAME}`,
`${MemoryType.KMP_Alloc_NAME}`, `${MemoryType.KMP_Free_NAME}`,
`${MemoryType.DART_HEAP_Alloc_NAME}`, `${MemoryType.DART_HEAP_Free_NAME}`,
`${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`, `${MemoryType.ARKTS_STATIC_HEAP_Free_NAME}`,
`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`, `${MemoryType.RN_HERMES_HEAP_Free_NAME}`,
`${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Free_NAME}`,
`${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Free_NAME}`
]
: [
`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.ARKTS_Alloc_NAME}`,
`${MemoryType.JS_Alloc_NAME}`, `${MemoryType.DART_HEAP_Alloc_NAME}`,
`${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`,
`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`,
`${MemoryType.KMP_Alloc_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`
];
case MemoryBasicType.NATIVE_MEMORY[2]:
return isStat
? [MemoryStatisticType.MALLOC, MemoryStatisticType.ARK_GLOBAL_HANDLE, MemoryStatisticType.ARK_LOCAL_HANDLE]
: needFree
? [`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.MEMORY_M_FREE_NAME}`,
`${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Free_NAME}`,
`${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Free_NAME}`
]
: [`${MemoryType.MEMORY_M_ALLOC_NAME}`, `${MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME}`, `${MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[3]:
return isStat
? [MemoryStatisticType.ARKTS]
: needFree
? [`${MemoryType.ARKTS_Alloc_NAME}`, `${MemoryType.ARKTS_Free_NAME}`]
: [`${MemoryType.ARKTS_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[4]:
return isStat
? [MemoryStatisticType.JS]
: needFree
? [`${MemoryType.JS_Alloc_NAME}`, `${MemoryType.JS_Free_NAME}`]
: [`${MemoryType.JS_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[5]:
return isStat
? [MemoryStatisticType.DART_HEAP]
: needFree
? [`${MemoryType.DART_HEAP_Alloc_NAME}`, `${MemoryType.DART_HEAP_Free_NAME}`]
: [`${MemoryType.DART_HEAP_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[6]:
return isStat
? [MemoryStatisticType.ARKTS_STATIC_HEAP]
: needFree
? [`${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`, `${MemoryType.ARKTS_STATIC_HEAP_Free_NAME}`]
: [`${MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[7]:
return isStat
? [MemoryStatisticType.RN]
: needFree
? [`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`, `${MemoryType.RN_HERMES_HEAP_Free_NAME}`]
: [`${MemoryType.RN_HERMES_HEAP_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[8]:
return isStat
? [MemoryStatisticType.KMP]
: needFree
? [`${MemoryType.KMP_Alloc_NAME}`, `${MemoryType.KMP_Free_NAME}`]
: [`${MemoryType.KMP_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[9]:
return isStat
? [MemoryStatisticType.MMAP, MemoryStatisticType.FILE_PAGE_MSG, MemoryStatisticType.MEMORY_USING_MSG,
MemoryStatisticType.SO, MemoryStatisticType.ASHMEM, MemoryStatisticType.DMA]
: needFree
? [
`${MemoryType.MEMORY_M_MAP_NAME}`, `${MemoryType.MEMORY_M_UNMAP_NAME}`,
`${MemoryType.SO_Alloc_NAME}`, `${MemoryType.SO_Free_NAME}`,
`${MemoryType.ASHMEM_Alloc_NAME}`, `${MemoryType.ASHMEM_Free_NAME}`,
`${MemoryType.ION_Alloc_NAME}`, `${MemoryType.ION_Free_NAME}`
]
: [
`${MemoryType.MEMORY_M_MAP_NAME}`,
`${MemoryType.SO_Alloc_NAME}`, `${MemoryType.ASHMEM_Alloc_NAME}`,
`${MemoryType.ION_Alloc_NAME}`
];
case MemoryBasicType.NATIVE_MEMORY[10]:
return isStat
? [MemoryStatisticType.DMA]
: needFree
? [`${MemoryType.ION_Alloc_NAME}`, `${MemoryType.ION_Free_NAME}`]
: [`${MemoryType.ION_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[11]:
return isStat
? [MemoryStatisticType.ASHMEM]
: needFree
? [`${MemoryType.ASHMEM_Alloc_NAME}`, `${MemoryType.ASHMEM_Free_NAME}`]
: [`${MemoryType.ASHMEM_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[12]:
return isStat
? [MemoryStatisticType.SO]
: needFree
? [`${MemoryType.SO_Alloc_NAME}`, `${MemoryType.SO_Free_NAME}`]
: [`${MemoryType.SO_Alloc_NAME}`];
case MemoryBasicType.NATIVE_MEMORY[13]:
return isStat
? [MemoryStatisticType.MMAP, MemoryStatisticType.FILE_PAGE_MSG, MemoryStatisticType.MEMORY_USING_MSG]
: needFree
? [`${MemoryType.MEMORY_M_MAP_NAME}`, `${MemoryType.MEMORY_M_UNMAP_NAME}`]
: [`${MemoryType.MEMORY_M_MAP_NAME}`];
case MemoryBasicType.OTHER_SOURCE[1]:
return isStat
? [MemoryStatisticType.FD]
: needFree
? [`${MemoryType.FD_OPEN_NAME}`, `${MemoryType.FD_CLOSE_NAME}`]
: [`${MemoryType.FD_OPEN_NAME}`];
case MemoryBasicType.OTHER_SOURCE[2]:
return isStat
? [MemoryStatisticType.THREAD]
: needFree
? [`${MemoryType.THREAD_CREATE_NAME}`, `${MemoryType.THREAD_DESTROY_NAME}`]
: [`${MemoryType.THREAD_CREATE_NAME}`];
default:
return [];
}
};
function getMemoryTypeListKey(memoryType: MemoryTraceRowType, isStatistic: boolean): keyof SelectionParam {
switch (memoryType) {
case MemoryTraceRowType.ROW_TYPE_NATIVE_MEMORY:
return isStatistic ? 'nativeMemoryStatistic' : 'nativeMemory';
case MemoryTraceRowType.ROW_TYPE_OTHER_SOURCE:
return isStatistic ? 'otherSourceStatistic' : 'otherSource';
case MemoryTraceRowType.ROW_TYPE_GPU_MEMORY:
return isStatistic ? 'gpuMemoryStatistic' : 'gpuMemory';
default:
throw new Error(`Unsupported memory type: ${memoryType}`);
}
};
export function getCurrentTypes(selectParam: SelectionParam, memoryType: MemoryTraceRowType, isStatistic: boolean, needFree: boolean = true): Array<string | number> {
const key = getMemoryTypeListKey(memoryType, isStatistic);
const typeList = selectParam[key];
const targetFilters: Array<number | string> = [];
if (!Array.isArray(typeList)) {
return [];
}
for (const type of typeList) {
targetFilters.push(...mapTypeToFilters(type, isStatistic, needFree));
}
return targetFilters;
}
export interface TraceRowMemoryConfig {
allProcess: Array<{ pid: number; ipid: number; }>;
statisticData: string[];
normalData: string[];
currentIPid: number;
memoryType: MemoryTraceRowType;
setCurrentIPid: (ipid: number) => void;
}
export function getEventTypeNameFromTypeId(type: number): string {
switch (type) {
case MemoryStatisticType.MALLOC:
return MemoryType.MEMORY_M_ALLOC_NAME;
case MemoryStatisticType.MMAP:
return MemoryType.MEMORY_M_MAP_NAME;
case MemoryStatisticType.FILE_PAGE_MSG:
return MemoryType.MEMORY_M_FILE_PAGE_MSG;
case MemoryStatisticType.MEMORY_USING_MSG:
return MemoryType.MEMORY_M_MEMORY_USING_MSG;
case MemoryStatisticType.FD:
return MemoryType.FD_OPEN_NAME;
case MemoryStatisticType.THREAD:
return MemoryType.THREAD_CREATE_NAME;
case MemoryStatisticType.GPU_VK:
return MemoryType.GPU_VK_Alloc_NAME;
case MemoryStatisticType.GPU_GLES:
return MemoryType.GPU_GLES_Alloc_NAME;
case MemoryStatisticType.GPU_CL:
return MemoryType.GPU_CL_Alloc_NAME;
case MemoryStatisticType.SO:
return MemoryType.SO_Alloc_NAME;
case MemoryStatisticType.ARKTS:
return MemoryType.ARKTS_Alloc_NAME;
case MemoryStatisticType.JS:
return MemoryType.JS_Alloc_NAME;
case MemoryStatisticType.KMP:
return MemoryType.KMP_Alloc_NAME;
case MemoryStatisticType.ASHMEM:
return MemoryType.ASHMEM_Alloc_NAME;
case MemoryStatisticType.DMA:
return MemoryType.ION_Alloc_NAME;
case MemoryStatisticType.DART_HEAP:
return MemoryType.DART_HEAP_Alloc_NAME;
case MemoryStatisticType.ARKTS_STATIC_HEAP:
return MemoryType.ARKTS_STATIC_HEAP_Alloc_NAME;
case MemoryStatisticType.RN:
return MemoryType.RN_HERMES_HEAP_Alloc_NAME;
case MemoryStatisticType.ARK_GLOBAL_HANDLE:
return MemoryType.ARK_GLOBAL_HANDLE_Alloc_NAME;
case MemoryStatisticType.ARK_LOCAL_HANDLE:
return MemoryType.ARK_LOCAL_HANDLE_Alloc_NAME;
default:
return '';
}
}