meminsight-test-demo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +36 -0
  3. package/docs/Build.md +68 -0
  4. package/docs/Interface.md +35 -0
  5. package/docs/UserGuide.md +332 -0
  6. package/docs/resources/analyzer.png +0 -0
  7. package/docs/resources/cfg_filter_filetype_json.png +0 -0
  8. package/docs/resources/filetype_txt.png +0 -0
  9. package/docs/resources/framework.png +0 -0
  10. package/docs/resources/output.png +0 -0
  11. package/docs/resources/process.png +0 -0
  12. package/package.json +54 -0
  13. package/packages/cfg/ArkStatCfg.json +33 -0
  14. package/packages/core/jest.config.js +8 -0
  15. package/packages/core/package.json +61 -0
  16. package/packages/core/src/Index.ts +53 -0
  17. package/packages/core/src/analyzer/AnalysisInfo.ts +298 -0
  18. package/packages/core/src/analyzer/ArkAnalyzer.ts +42 -0
  19. package/packages/core/src/analyzer/ArkCmpCfg.ts +22 -0
  20. package/packages/core/src/analyzer/ArkCompareAnalyzer.ts +173 -0
  21. package/packages/core/src/analyzer/ArkLeakAnalyzer.ts +196 -0
  22. package/packages/core/src/analyzer/ArkSerializer.ts +163 -0
  23. package/packages/core/src/analyzer/ArkStatAnalyzer.ts +191 -0
  24. package/packages/core/src/analyzer/ArkStatCfg.ts +77 -0
  25. package/packages/core/src/analyzer/ArkTracePath.ts +269 -0
  26. package/packages/core/src/analyzer/ArkTracer.ts +42 -0
  27. package/packages/core/src/analyzer/ArkXAnalyzer.ts +631 -0
  28. package/packages/core/src/analyzer/IAnalyzer.ts +27 -0
  29. package/packages/core/src/file/FileReader.ts +82 -0
  30. package/packages/core/src/file/FileService.ts +50 -0
  31. package/packages/core/src/file/FileWriter.ts +148 -0
  32. package/packages/core/src/report/Reporter.ts +81 -0
  33. package/packages/core/src/report/templates/template.ejs +101 -0
  34. package/packages/core/src/report/templates/template.ts +103 -0
  35. package/packages/core/src/shell/DeviceShell.ts +179 -0
  36. package/packages/core/src/shell/Shell.ts +99 -0
  37. package/packages/core/src/types/Constants.ts +16 -0
  38. package/packages/core/src/types/LeakTypes.ts +21 -0
  39. package/packages/core/src/types/OhosTypes.ts +115 -0
  40. package/packages/core/src/utils/Common.ts +37 -0
  41. package/packages/core/src/utils/Finder.ts +390 -0
  42. package/packages/core/src/utils/Loader.ts +53 -0
  43. package/packages/core/src/utils/Log.ts +252 -0
  44. package/packages/core/src/utils/Output.ts +271 -0
  45. package/packages/core/tsconfig.json +10 -0
  46. package/packages/exampletools/package.json +52 -0
  47. package/packages/exampletools/src/MemTest.ts +64 -0
  48. package/packages/exampletools/tsconfig.json +15 -0
  49. package/packages/meminsight/jest.config.js +8 -0
  50. package/packages/meminsight/package.json +52 -0
  51. package/packages/meminsight/src/Index.ts +4 -0
  52. package/packages/meminsight/src/Version.ts +7 -0
  53. package/packages/meminsight/src/process/ArkCompareProc.ts +160 -0
  54. package/packages/meminsight/src/process/ArkGCProc.ts +61 -0
  55. package/packages/meminsight/src/process/ArkLeakProc.ts +47 -0
  56. package/packages/meminsight/src/process/ArkStatProc.ts +320 -0
  57. package/packages/meminsight/src/process/ArkXProc.ts +73 -0
  58. package/packages/meminsight/src/process/HMemXProc.ts +50 -0
  59. package/packages/meminsight/src/process/IProcess.ts +12 -0
  60. package/packages/meminsight/tsconfig.json +15 -0
  61. package/packages/stack/README.md +31 -0
  62. package/packages/stack/libs/hstack_lib-1.0.0.tgz +0 -0
  63. package/packages/stack/libs/hstack_lib-1.0.1.tgz +0 -0
  64. package/packages/stack/libs/hstack_lib-1.0.4.tgz +0 -0
  65. package/packages/stack/libs/lib_list.json +34 -0
  66. package/packages/stack/package.json +27 -0
  67. package/packages/stack/src/Index.js +29 -0
  68. package/packages/stack/src/StackTracer.js +53 -0
  69. package/packages/templates/ArkLeaks.template +9 -0
  70. package/packages/templates/ArkNodes.template +9 -0
  71. package/packages/templates/ArkPaths.template +9 -0
  72. package/test/scripts/merge.py +145 -0
  73. package/test/scripts/stat.py +175 -0
  74. package/test/test_ark_stat_proc.sh +14 -0
  75. package/tsconfig.base.json +38 -0
  76. package/tsconfig.json +8 -0
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "meminsight-test-demo",
3
+ "version": "1.0.0",
4
+ "description": "meminsight for memory analysis.",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "commander": "^13.1.0",
8
+ "fs-extra": "^11.2.1",
9
+ "moment": "^2.29.4",
10
+ "winston": "^3.11.0"
11
+ },
12
+ "devDependencies": {
13
+ "@babel/cli": "^7.27.2",
14
+ "@babel/core": "^7.27.1",
15
+ "@babel/preset-env": "^7.27.2",
16
+ "@types/blessed": "^0.1.19",
17
+ "@types/fs-extra": "^11.0.4",
18
+ "@types/jest": "^29.1.1",
19
+ "@types/node": "^22.15.17",
20
+ "jest": "^29.1.1",
21
+ "ts-jest": "^29.1.1",
22
+ "ts-node": "^10.9.2",
23
+ "typescript": "^5.8.3"
24
+ },
25
+ "workspaces": [
26
+ "./packages/core",
27
+ "./packages/meminsight",
28
+ "./packages/exampletools"
29
+ ],
30
+ "scripts": {
31
+ "dev": "tsc -b -w",
32
+ "build": "npm run clean && npm run build --workspaces",
33
+ "test": "npm run test --workspaces --if-present",
34
+ "publish": "npm run publish-patch --workspaces",
35
+ "clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo && npm run clean --workspaces",
36
+ "clean-all": "npm run clean-all --workspaces && rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo && rm -rf ./node_modules && rm -rf ./output",
37
+ "pkg-meminsight": "pkg -t node18 --output=./dist/meminsight --public -C GZip packages/meminsight/package.json",
38
+ "pkg-exampletools": "pkg -t node18 --output=./dist/exampletools --public -C GZip packages/exampletools/package.json"
39
+ },
40
+ "devEngines": {
41
+ "node": "16.x | 18.x | 20.x | 22.x",
42
+ "npm": "7.x"
43
+ },
44
+ "pkg": {
45
+ "scripts": {
46
+ "postinstall": "npm run build"
47
+ },
48
+ "assets": [
49
+ "dist/**/*",
50
+ "packages/**/package.json"
51
+ ],
52
+ "output": "dist"
53
+ }
54
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "Node": {
3
+ "enableTypeWhiteList": true,
4
+ "typeWhiteList": ["object", "closure"],
5
+ "enableTypeBlackList": false,
6
+ "typeBlackList": [],
7
+ "enableNameWhiteList": false,
8
+ "nameWhiteList": [],
9
+ "enableNameBlackList": true,
10
+ "nameBlackList": [],
11
+ "enableId": true,
12
+ "enableType": true,
13
+ "enableName": true,
14
+ "enableSelfSize": true,
15
+ "enableRetainedSize": true
16
+ },
17
+ "Path": {
18
+ "enableDistance": true,
19
+ "enableSelfSize": true,
20
+ "enableRetainedSize": true,
21
+ "enableNativeSize": false,
22
+ "enableShortest": true,
23
+ "enableShortestLength": false,
24
+ "shortestLength": 0,
25
+ "enableAggration": true,
26
+ "aggrationLength": 3,
27
+ "aggrationDescending": true,
28
+ "enableMinRetainedSize": true,
29
+ "minRetainedSize": 1048576,
30
+ "enableMaxRetainedSize": false,
31
+ "maxRetainedSize": 0
32
+ }
33
+ }
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} **/
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ transform: {
6
+ '^.+\\.ts?$': 'ts-jest',
7
+ },
8
+ };
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@meminsight/core",
3
+ "version": "1.0.0",
4
+ "description": "meminsight core library is for memory analysis.",
5
+ "author": {
6
+ "name": ""
7
+ },
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "jest",
11
+ "publish": "npm publish",
12
+ "clean": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo",
13
+ "clean-all": "rm -rf ./dist && rm -rf ./tsconfig.tsbuildinfo && rm -rf ./node_modules && find ./src -type f -name \"*.js\" -exec rm -f {} +"
14
+ },
15
+ "main": "dist/Index.js",
16
+ "types": "dist/Index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/Index.d.ts",
20
+ "default": "./dist/Index.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "./dist",
26
+ "License"
27
+ ],
28
+ "engines": {
29
+ "node": ">=16.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@memlab/core": "^1.0.40",
33
+ "@memlab/heap-analysis": "^1.0.40",
34
+ "@types/node": "^22.14.1",
35
+ "@types/jest": "^29.1.1",
36
+ "@types/ejs": "^3.1.5",
37
+ "ejs": "^3.1.10",
38
+ "axios": "^1.1.3",
39
+ "ansi": "^0.3.1",
40
+ "fs-extra": "^11.2.0",
41
+ "string-width": "^7.2.0",
42
+ "babar": "^0.2.0",
43
+ "chalk": "^5.4.1",
44
+ "minimist": "^1.2.8",
45
+ "util.promisify": "^1.1.1",
46
+ "node-xlsx": "^0.24.0",
47
+ "jest": "^29.1.1",
48
+ "typescript": "^5.3.3"
49
+ },
50
+ "devDependencies": {
51
+ "@types/fs-extra": "^11.0.4",
52
+ "@types/node": "^22.14.1",
53
+ "@types/minimist": "^1.2.2",
54
+ "@types/jest": "^29.1.1",
55
+ "jest": "^29.7.0",
56
+ "ts-jest": "^29.1.1",
57
+ "ts-node": "^10.9.1",
58
+ "typescript": "^5.3.3"
59
+ },
60
+ "workspaces": []
61
+ }
@@ -0,0 +1,53 @@
1
+ // types
2
+ export {
3
+ IDataInfo,
4
+ AppInfo,
5
+ DeviceInfo,
6
+ HeapFileInfo,
7
+ HeapInfos,
8
+ OsInfo,
9
+ UrlInfo
10
+ } from './types/OhosTypes';
11
+
12
+ // utils
13
+ export { ILogger, ILoggable, Log, LogType } from './utils/Log';
14
+ export { Loader } from './utils/Loader';
15
+ export { Finder } from './utils/Finder';
16
+ export {
17
+ IOutput,
18
+ OutputType,
19
+ OutputCfg,
20
+ OutputFactory,
21
+ ConsoleData,
22
+ ConsoleTableData,
23
+ TextData,
24
+ JsonData,
25
+ HtmlData
26
+ } from './utils/Output';
27
+
28
+ // file
29
+ export { IReader, BaseReader, JsonReader } from './file/FileReader';
30
+ export { IWriter, BaseWriter, TextWriter, JsonWriter, HtmlWriter } from './file/FileWriter';
31
+
32
+ // analyzer
33
+ export { IAnalyzer } from './analyzer/IAnalyzer';
34
+ export { ArkAnalyzer } from './analyzer/ArkAnalyzer';
35
+ export { ArkStatAnalyzer } from './analyzer/ArkStatAnalyzer';
36
+ export { ArkCompareAnalyzer } from './analyzer/ArkCompareAnalyzer';
37
+ export { ArkLeakAnalyzer } from './analyzer/ArkLeakAnalyzer';
38
+ export { ArkStatCfg, defaultArkStatCfg } from './analyzer/ArkStatCfg';
39
+ export { ArkCmpCfg, defaultArkCmpCfg } from './analyzer/ArkCmpCfg';
40
+ export { ArkXAnalyzer } from './analyzer/ArkXAnalyzer';
41
+ export {
42
+ ArkTracePathItem,
43
+ ArkNodeTracePath,
44
+ ArkNodePathIndexes,
45
+ ArkNodes,
46
+ ArkNodesMap
47
+ } from './analyzer/ArkTracePath';
48
+ export { ArkTracer, ArkTracePathFilter, ArkTracePathOutput } from './analyzer/ArkTracer';
49
+ export { ArkSerializer } from './analyzer/ArkSerializer';
50
+
51
+ // shell
52
+ export { IShell, ShellArgs, Shell } from './shell/Shell';
53
+ export { DeviceShell } from './shell/DeviceShell';
@@ -0,0 +1,298 @@
1
+ import { ReportData } from "../report/Reporter";
2
+
3
+ export interface IBaseInfo {
4
+ toReportData: () => ReportData;
5
+ }
6
+
7
+ export class ClassInfo {
8
+ public className: string; // 指定类名
9
+ public count: number; // 指定类总数量
10
+ public retainedSize: number; // 指定类总retainedSize
11
+ public selfSize: number; // 指定类总selfSize
12
+ public retainedSizeTotalHeapPercent: number; // 指定类总retainedSize占TotalHeapSize百分比
13
+ public selfSizeTotalHeapPercent: number; // 指定类总selfSize占TotalHeapSize百分比
14
+ public retainedSizeTotalRetainedPercent: number; // 指定类总retainedSize占TotalRetainedSize百分比
15
+ public selfSizeTotalSelfPercent: number; // 指定类总selfSize占TotalSelfSize百分比
16
+
17
+ toString(): string {
18
+ return `Class Name: ${this.className},
19
+ Count: ${this.count},
20
+ Retained Size: ${(this.retainedSize / 1024).toFixed(2)} KB,
21
+ RetainedSizeTotalHeapPercent: ${this.retainedSizeTotalHeapPercent.toFixed(2)}%,
22
+ Shallow Size: ${(this.selfSize / 1024).toFixed(2)} KB,
23
+ ShallowSizeTotalHeapPercent: ${this.selfSizeTotalHeapPercent.toFixed(2)}%`
24
+ }
25
+ };
26
+
27
+ export class DistanceInfo {
28
+ public objectNameOrType: string;// 对象名称或类型
29
+ public distance: number; // 最短引用链某一类Distance
30
+ public count: number; // 该类Distance总数量
31
+ public retainedSize: number; // 该类Distance总retainedSize
32
+ public selfSize: number; // 该类Distance总selfSize
33
+ public retainedSizeTotalHeapPercent: number; // 该类Distance总retainedSize占TotalHeapSize百分比
34
+ public selfSizeTotalHeapPercent: number; // 该类Distance总selfSize占TotalHeapSize百分比
35
+ public retainedSizeTotalRetainedPercent: number; // 该类Distance总retainedSize占TotalRetainedSize百分比
36
+ public selfSizeTotalSelfPercent: number; // 该类Distance总selfSize占TotalSelfSize百分比
37
+
38
+ toString(): string {
39
+ return `Distance: ${this.distance},
40
+ Count: ${this.count},
41
+ Retained Size: ${(this.retainedSize / 1024).toFixed(2)} KB,
42
+ RetainedSizeTotalHeapPercent: ${this.retainedSizeTotalHeapPercent.toFixed(2)}%,
43
+ Shallow Size: ${(this.selfSize / 1024).toFixed(2)} KB,
44
+ ShallowSizeTotalHeapPercent: ${this.selfSizeTotalHeapPercent.toFixed(2)}%`
45
+ }
46
+ }
47
+
48
+ export class ShortestPathInfo {
49
+ public shortestPathStr: string; // 最短引用链节点名称
50
+ public shortestPathIds: number[]; // 最短引用链节点Id
51
+ public count: number; // 相同最短引用链数量
52
+ public retainedSize: number; // 相同最短引用链总保留大小
53
+ public selfSize: number; // 相同最短引用链总selfSize
54
+ public retainedSizeTotalHeapPercent: number; // 该类Distance总retainedSize占TotalHeapSize百分比
55
+ public selfSizeTotalHeapPercent: number; // 该类Distance总selfSize占TotalHeapSize百分比
56
+ public retainedSizeTotalRetainedPercent: number; // 该类Distance总retainedSize占TotalRetainedSize百分比
57
+ public selfSizeTotalSelfPercent: number; // 该类Distance总selfSize占TotalSelfSize百分比
58
+
59
+ toString(): string {
60
+ return `ShortestPath: ${this.shortestPathStr},
61
+ Count: ${this.count},
62
+ Retained Size: ${(this.retainedSize / 1024).toFixed(2)} KB,
63
+ RetainedSizeTotalHeapPercent: ${this.retainedSizeTotalHeapPercent.toFixed(2)}%,
64
+ Shallow Size: ${(this.selfSize / 1024).toFixed(2)} KB,
65
+ ShallowSizeTotalHeapPercent: ${this.selfSizeTotalHeapPercent.toFixed(2)}%`
66
+ }
67
+ }
68
+
69
+ export class PropertyInfo {
70
+ public propName: string; // 属性名
71
+ public propShortestPath: string; // 属性最短引用链
72
+ public count: number; // 该属性总数量
73
+ public retainedSize: number; // 该属性总retainedSize
74
+ public selfSize: number; // 该属性总selfSize
75
+ public retainedSizeTotalHeapPercent: number; // 该属性总retainedSize占TotalHeapSize百分比
76
+ public selfSizeTotalHeapPercent: number; // 该属性总selfSize占TotalHeapSize百分比
77
+ public retainedSizeTotalRetainedPercent: number; // 该属性总retainedSize占TotalRetainedSize百分比
78
+ public selfSizeTotalSelfPercent: number; // 该该属性总selfSize占TotalRetainedSize百分比
79
+
80
+ toString(): string {
81
+ return `Property Name: ${this.propName || ''},
82
+ Property ShortestPath: ${this.propShortestPath || ''},
83
+ Count: ${this.count},
84
+ Retained Size: ${(this.retainedSize / 1024).toFixed(2)} KB,
85
+ RetainedSizeTotalHeapPercent: ${this.retainedSizeTotalHeapPercent.toFixed(2)}%,
86
+ Shallow Size: ${(this.selfSize / 1024).toFixed(2)} KB,
87
+ ShallowSizeTotalHeapPercent: ${this.selfSizeTotalHeapPercent.toFixed(2)}%`
88
+ }
89
+ }
90
+
91
+ /**
92
+ * 分析数据节点
93
+ */
94
+ abstract class BaseAnalysisInfo implements IBaseInfo {
95
+ public name: string; // 名称信息:分析数据节点名称
96
+ public type: string; // 类型信息:js_shared_object | JSObject | JSFunction | framework | global_env ...
97
+ public desc: string; // 描述信息:分析数据节点描述
98
+ public scope: string; // 范围信息:aggregation | statistics
99
+
100
+ public totalHeapSize: number;
101
+ public totalRetainedSize?: number;
102
+ public totalSelfSize?: number;
103
+ public totalCount?: number;
104
+
105
+ public className?: string;
106
+ public classInfos?: ClassInfo[];
107
+ public distanceInfos?: DistanceInfo[];
108
+ public shortestPathInfos?: ShortestPathInfo[];
109
+ public propertyInfos?: PropertyInfo[];
110
+
111
+ protected getFeature() : string {
112
+ return `${this.type} ${this.desc}`;
113
+ }
114
+
115
+ protected getMessage() : string[] {
116
+ return [
117
+ `Total Heap Size: ${(this.totalHeapSize / 1024 / 1024).toFixed(2)} MB`,
118
+ `All ${this.type} Retained Size: ${(this.totalRetainedSize!! / 1024).toFixed(2)} KB`,
119
+ `All ${this.type} Shallow Size: ${(this.totalSelfSize!! / 1024).toFixed(2)} KB`,
120
+ `Count of ${this.type}: ${this.totalCount}`
121
+ ];
122
+ }
123
+
124
+ protected getColumns(): Map<string, string> {
125
+ return new Map();
126
+ }
127
+
128
+ protected getData() : Record<string, any> {
129
+ return []
130
+ }
131
+
132
+ toReportData(): ReportData {
133
+ return {
134
+ feature: this.getFeature(),
135
+ messages: this.getMessage(),
136
+ columns: this.getColumns(),
137
+ data: this.getData()
138
+ } as ReportData;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * 按类名聚合分析数据节点信息
144
+ */
145
+ export class AggregationByClassName extends BaseAnalysisInfo {
146
+ public name: string = AggregationByClassName.name;
147
+ public desc: string = "按类名聚合";
148
+
149
+ protected getColumns(): Map<string, string> {
150
+ return new Map([
151
+ ['className', 'Class Name'],
152
+ ['count', 'Count'],
153
+ ['retainedSize', 'Retained Size(KB)'],
154
+ ['selfSize', 'Shallow Size(KB)'],
155
+ ['retainedSizeTotalHeapPercent', 'Retained Size Ratio(%)'],
156
+ ['selfSizeTotalHeapPercent', 'Shallow Size Ratio(%)']
157
+ ]);
158
+ }
159
+
160
+ protected getData(): Record<string, any> {
161
+ let data: Record<string, any> = [];
162
+ this.classInfos?.forEach(info => {
163
+ data.push({
164
+ ...info,
165
+ retainedSize: `${(info.retainedSize / 1024).toFixed(2)}KB`,
166
+ selfSize: `${(info.selfSize / 1024).toFixed(2)}KB`,
167
+ retainedSizeTotalHeapPercent: `${(info.retainedSizeTotalHeapPercent).toFixed(2)}%`,
168
+ selfSizeTotalHeapPercent: `${(info.selfSizeTotalHeapPercent).toFixed(2)}%`
169
+ });
170
+ })
171
+ return data;
172
+ }
173
+ }
174
+
175
+ /**
176
+ * 按最短引用链聚合分析数据节点信息
177
+ */
178
+ export class AggregationByShortestPath extends BaseAnalysisInfo {
179
+ public name: string = AggregationByShortestPath.name;
180
+ public desc: string = "按最短引用链聚合";
181
+
182
+ protected getColumns(): Map<string, string> {
183
+ return new Map([
184
+ ['shortestPathStr', 'Shortest Path To GCRoot'],
185
+ ['count', 'Count'],
186
+ ['retainedSize', 'Retained Size (KB)'],
187
+ ['selfSize', 'Shallow Size (KB)'],
188
+ ['retainedSizeTotalHeapPercent', 'Retained Size Ratio(%)'],
189
+ ['selfSizeTotalHeapPercent', 'Shallow Size Ratio(%)']
190
+ ]);
191
+ }
192
+
193
+ protected getData(): Record<string, any> {
194
+ let data: Record<string, any> = [];
195
+ this.shortestPathInfos?.forEach(info => {
196
+ data.push({
197
+ ...info,
198
+ retainedSize: `${(info.retainedSize / 1024).toFixed(2)}KB`,
199
+ selfSize: `${(info.selfSize / 1024).toFixed(2)}KB`,
200
+ retainedSizeTotalHeapPercent: `${(info.retainedSizeTotalHeapPercent).toFixed(2)}%`,
201
+ selfSizeTotalHeapPercent: `${(info.selfSizeTotalHeapPercent).toFixed(2)}%`,
202
+ });
203
+ })
204
+ return data;
205
+ }
206
+ }
207
+
208
+ export class AggregationByProperty extends BaseAnalysisInfo {
209
+ public name: string = AggregationByProperty.name;
210
+ public desc: string = "按属性最短引用路径聚合";
211
+
212
+ protected getColumns(): Map<string, string> {
213
+ return new Map([
214
+ ['propName', 'Property Name'],
215
+ ['propShortestPath', 'Property Shortest Path To GCRoot'],
216
+ ['count', 'Count'],
217
+ ['retainedSize', 'Retained Size(KB)'],
218
+ ['selfSize', 'Shallow Size(KB)'],
219
+ ['retainedSizeTotalHeapPercent', 'Retained Size Ratio(%)'],
220
+ ['selfSizeTotalHeapPercent', 'Shallow Size Ratio(%)'],
221
+ ]);
222
+ }
223
+
224
+ protected getData(): Record<string, any> {
225
+ let data: Record<string, any> = [];
226
+ this.propertyInfos?.forEach(info => {
227
+ // 处理百分比数据与size数据
228
+ data.push({
229
+ ...info,
230
+ retainedSize: `${(info.retainedSize / 1024).toFixed(2)}KB`,
231
+ selfSize: `${(info.selfSize / 1024).toFixed(2)}KB`,
232
+ retainedSizeTotalHeapPercent: `${(info.retainedSizeTotalHeapPercent).toFixed(2)}%`,
233
+ selfSizeTotalHeapPercent: `${(info.selfSizeTotalHeapPercent).toFixed(2)}%`,
234
+ });
235
+ })
236
+ return data;
237
+ }
238
+ }
239
+
240
+ export class StatisticsByClassName extends BaseAnalysisInfo {
241
+ public name: string = StatisticsByClassName.name;
242
+ public desc: string = "按类名统计";
243
+
244
+ protected getColumns(): Map<string, string> {
245
+ return new Map([
246
+ ['className', 'Class Name'],
247
+ ['count', 'Count'],
248
+ ['retainedSize', 'Retained Size(KB)'],
249
+ ['selfSize', 'Shallow Size(KB)'],
250
+ ['retainedSizeTotalHeapPercent', 'Retained Size Ratio(%)'],
251
+ ['selfSizeTotalHeapPercent', 'Shallow Size Ratio(%)'],
252
+ ]);
253
+ }
254
+
255
+ protected getData(): Record<string, any> {
256
+ let data: Record<string, any> = [];
257
+ this.distanceInfos?.forEach(info => {
258
+ data.push({
259
+ ...info,
260
+ retainedSize: `${(info.retainedSize / 1024).toFixed(2)}KB`,
261
+ selfSize: `${(info.selfSize / 1024).toFixed(2)}KB`,
262
+ retainedSizeTotalHeapPercent: `${(info.retainedSizeTotalHeapPercent).toFixed(2)}%`,
263
+ selfSizeTotalHeapPercent: `${(info.selfSizeTotalHeapPercent).toFixed(2)}%`,
264
+ });
265
+ })
266
+ return data;
267
+ }
268
+ }
269
+
270
+ export class StatisticsByDistance extends BaseAnalysisInfo {
271
+ public name: string = StatisticsByDistance.name;
272
+ public desc: string = "按距离统计";
273
+
274
+ protected getColumns(): Map<string, string> {
275
+ return new Map([
276
+ ['distance', 'Distance'],
277
+ ['count', 'Count'],
278
+ ['retainedSize', 'Retained Size(KB)'],
279
+ ['selfSize', 'Shallow Size(KB)'],
280
+ ['retainedSizeTotalHeapPercent', 'Retained Size Ratio(%)'],
281
+ ['selfSizeTotalHeapPercent', 'Shallow Size Ratio(%)'],
282
+ ]);
283
+ }
284
+
285
+ protected getData(): Record<string, any> {
286
+ let data: Record<string, any> = [];
287
+ this.distanceInfos?.forEach(info => {
288
+ data.push({
289
+ ...info,
290
+ retainedSize: `${(info.retainedSize / 1024).toFixed(2)}KB`,
291
+ selfSize: `${(info.selfSize / 1024).toFixed(2)}KB`,
292
+ retainedSizeTotalHeapPercent: `${(info.retainedSizeTotalHeapPercent).toFixed(2)}%`,
293
+ selfSizeTotalHeapPercent: `${(info.selfSizeTotalHeapPercent).toFixed(2)}%`,
294
+ });
295
+ })
296
+ return data;
297
+ }
298
+ }
@@ -0,0 +1,42 @@
1
+ import { IAnalyzer } from "./IAnalyzer";
2
+
3
+ /**
4
+ * Ark 分析器
5
+ */
6
+ export abstract class ArkAnalyzer implements IAnalyzer {
7
+ protected type: string = 'ark-analyzer';
8
+ protected configuration: any;
9
+
10
+ /**
11
+ * 解析
12
+ * @param args 解析参数
13
+ * @returns
14
+ */
15
+ public async analyze(args: any[]) : Promise<any> {
16
+ return undefined;
17
+ }
18
+
19
+ /**
20
+ * 设置解析器配置
21
+ * @param cfg 解析器配置
22
+ */
23
+ public setConfig(cfg: any) : void {
24
+ this.configuration = cfg
25
+ }
26
+
27
+ /**
28
+ * 获取解析器配置
29
+ * @returns 解析器配置
30
+ */
31
+ public getConfig(): any {
32
+ return this.configuration;
33
+ }
34
+
35
+ /**
36
+ * 获取解析器类型
37
+ * @returns 解析器类型
38
+ */
39
+ public getType(): string {
40
+ return this.type;
41
+ }
42
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Ark Compare Configuration
3
+ */
4
+ export type ArkCmpCfg = {
5
+ Node: {
6
+ enableNameWhiteList: boolean,
7
+ nameWhiteList: string[]
8
+ }
9
+ }
10
+
11
+ /**
12
+ * Ark Compare default configuration
13
+ * @returns default configuration
14
+ */
15
+ export function defaultArkCmpCfg() : ArkCmpCfg {
16
+ return {
17
+ Node: {
18
+ enableNameWhiteList: false,
19
+ nameWhiteList: []
20
+ }
21
+ }
22
+ }