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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # ByteFun MemInsight
2
+ ![](https://img.shields.io/badge/license-Apache%202-green.svg)
3
+ [![](https://img.shields.io/badge/env-Node16.x+-blue.svg)](https://nodejs.org/en/download/)
4
+ [![](https://img.shields.io/badge/lang-TypeScript-orange.svg)](https://www.typescriptlang.org/download/)
5
+
6
+ ByteFun MemInsight 是面向鸿蒙生态伙伴的一款开源内存分析引擎,包含meminsight命令行工具和npm包等组件。
7
+
8
+ ## 快速开始
9
+
10
+ [**User Guide**](./docs/UserGuide.md)
11
+
12
+ ## 框架介绍
13
+
14
+ ![](./docs/resources/framework.png)
15
+
16
+ ## 功能介绍
17
+
18
+ ### 快照解析器
19
+
20
+ ![](./docs/resources/analyzer.png)
21
+
22
+ #### 【StatisticAnalyzer】支持内存快照统计分析
23
+ 适用场景:单快照分析
24
+
25
+ #### 【CompareAnalyzer】支持内存快照比较分析
26
+ 适用场景:双快照分析
27
+
28
+ #### 【XAnalyzer】支持内存快照统计&聚合分析
29
+ 适用场景:单快照/多快照统计&聚合分析
30
+
31
+ #### 【LeakAnalyzer】支持内存快照泄露分析(待规划)
32
+ 适用场景:多快照分析
33
+
34
+ ## 构建编译
35
+
36
+ [构建编译指导链接](./docs/Build.md)
package/docs/Build.md ADDED
@@ -0,0 +1,68 @@
1
+ # ByteFun MemInsight 构建
2
+
3
+ 构建支持命令行工具和 npm 包两种方式。
4
+
5
+ ## 构建步骤
6
+
7
+ 1. 安装 node 环境,node 版本要求 >= 16.x, npm 版本要求 >= 7.x
8
+
9
+ 2. Git 下载 MemInsight 代码仓
10
+
11
+ 3. 进入 MemInsight 目录,执行 npm install
12
+
13
+ 4. 执行 npm run build
14
+
15
+ 5. 构建成功,
16
+
17
+ (1) npm 包生成在 ./node_modules/@meminsight 目录下
18
+
19
+ (2) npm 包生成在 .packages/core/dist 和 .packages/meminsight/dist 目录下
20
+
21
+ 6. 执行 npm run pkg-meminsight
22
+
23
+ 7. 构建成功,命令行工具生成在 ./dist 目录下,是一个可执行文件 meminsight
24
+
25
+ ## 构建说明
26
+
27
+ ### 运行 npm run build 失败,请重新执行 npm install
28
+
29
+ 可以依次执行以下命令:
30
+
31
+ ```bash
32
+ npm run clean-all
33
+ npm install
34
+ npm run build
35
+ ```
36
+
37
+ ### 运行 npm run pkg-meminsight 失败,请检查 pkg 是否安装成功
38
+
39
+ (1)执行以下命令并检查 pkg 版本
40
+
41
+ ```bash
42
+ $ npm install -g pkg
43
+ $ pkg --version
44
+ 5.8.1
45
+ ```
46
+
47
+ (2)打包可执行文件 meminsight
48
+ ```bash
49
+ $ npm run pkg-meminsight
50
+
51
+ > meminsight@1.0.0 pkg
52
+ > pkg -t node18 --output=./dist/meminsight --public -C GZip packages/meminsight/package.json
53
+
54
+ > pkg@5.8.1
55
+ compression: GZip
56
+ ...
57
+ ```
58
+ 在工程根目录下 dist 文件夹下生成 meminsight 可执行文件。
59
+
60
+ ### npm run pkg-meminsight 显示版本不匹配
61
+
62
+ ```bash
63
+ Error: Failed to load bindings
64
+ Error: The module was compiled against a different Node.js version
65
+ ```
66
+
67
+ 升级或降级 pkg 到与当前 Node.js 兼容的版本.
68
+ 如本工程 pkg 版本为 5.8.1,Node.js 版本为 16.19.1
@@ -0,0 +1,35 @@
1
+ ## ByteFun MemInsight MemInsight Analyzer Interfaces
2
+ | 接口 | 参数 |
3
+ |----|----|
4
+ |analyze(args: any[]) : Promise<any>|args: any[]:heapsnapshot文件路径|
5
+ |setConfig(cfg: any) : void|cfg: any 不同分析器 cfg 不同|
6
+ |getConfig(): any|获取解析器配置|
7
+ |getGCRoots() : Promise<Array<IHeapNode>>|获取所有GC根节点|
8
+ |getDetachedNodes() : Promise<Array<IHeapNode>>|获取所有分离节点|
9
+ |getNodesByConfig() : Promise<Array<IHeapNode>>|获取所有符合配置条件的节点|
10
+ |getArkNodesMap(...): Promise<ArkNodesMap>|参数见描述 [链接](#getarknodesmap)|
11
+
12
+ ## getArkNodesMap
13
+ ### 参数列表:
14
+ ```typescript
15
+ nameWhiteList: string[],
16
+ typeWhiteList: string[] = ['object'],
17
+ enableShortestPath: boolean = true,
18
+ enableAggrationPath: boolean = true,
19
+ maxAggrationLength = 3,
20
+ enableMinRetainedSize = false,
21
+ minRetainedSize = 1024 * 1024,
22
+ descending: boolean = true
23
+ ```
24
+ ### 参数描述
25
+ ```typescript
26
+ nameWhiteList: 节点名称白名单,空则包含所有节点名称;typeWhiteList: 节点类型白名单,必填字段;
27
+ enableShortestPath: 是否分析最短引用路径
28
+ enableAggrationPath: 是否聚合引用路径
29
+ maxAggrationLength: 筛选的最大最短引用路径个数
30
+ enableMinRetainedSize: 是否按retained size阈值过滤最短引用路径
31
+ minRetainedSize: retained size阈值
32
+ descending: 是否按引用次数降序获取聚合路径,默认true
33
+ getArkNodesMapByConfig() : Promise<ArkNodesMap | undefined>
34
+ 根据配置获取符合条件的节点信息,包括最短引用路径聚合路径信息
35
+ ```
@@ -0,0 +1,332 @@
1
+ # ByteFun MemInsight 使用介绍
2
+
3
+ ## meminsight 命令行工具
4
+
5
+ meminsight 命令行工具是一个基于node的可执行文件,使用简单方便。
6
+
7
+ ### help
8
+
9
+ ```bash
10
+ $./meminsight -h
11
+ Usage: meminsight [options] [command]
12
+
13
+ meminsight binary is a command tool for memory analysis.
14
+
15
+ Options:
16
+ -v, --version meminsight version
17
+ -h, --help display help for command
18
+
19
+ Commands:
20
+ ark-stat [options] ark statistic analysis process.
21
+ ark-compare [options] ark compare process.
22
+ ark-leak [options] ark leaks analysis process.
23
+ ark-gc [options] ark force gc process.
24
+ ark-x [options] ark-x analysis process.
25
+ help [command] display help for command
26
+ ```
27
+
28
+ ### ark-stat
29
+
30
+ ```bash
31
+ $ ./dist/meminsight ark-stat -h
32
+ Usage: meminsight ark-stat [options]
33
+
34
+ ark statistic analysis process.
35
+
36
+ Options:
37
+ -t, --target <target heapsnapshot file> target heapsnapshot file
38
+ -m, --mode <mode type>
39
+ mode type:
40
+ 1: get all detached nodes
41
+ 2: get all gc roots
42
+ 3: get node shortest path, node id is required
43
+ 4: get node aggration paths by configuration => Not Support
44
+ 5: get node by configuration
45
+ 6: get shared heap nodes. => Not Support
46
+
47
+ -i, --node_id <node id> node id
48
+ -c, --config <configuration file> configuration file
49
+ -o, --output <output folder path> output folder path (default: "./output")
50
+ -f, --output_file <output file type> output file type, console | txt | json | html. (default: "console")
51
+ -h, --help display help for command
52
+ ```
53
+ ### 示例
54
+
55
+ 1. 获取指定快照 Detached Nodes 并保存到 txt 文件
56
+
57
+ ```bash
58
+ $ ./meminsight ark-stat -t ../files/1.heapsnapshot -m 1 -i 1 -o ./output -f txt
59
+ | 2025-05-12T09:56:45.032 | [INFO] | meminsight-ArkStatProc: Analyzed successfully.
60
+ | 2025-05-12T09:56:45.034 | [WARN] | meminsight-ArkStatProc: No configuration found, use default config.
61
+ ......
62
+ | 2025-05-12T09:56:45.036 | [INFO] | meminsight-ArkStatProc: Set configuration successfully.
63
+ | 2025-05-12T09:56:45.036 | [INFO] | meminsight-ArkStatProc: mode:1; output:./output; type:txt
64
+ ```
65
+ 生成的 txt 文件如下,每一行包含了节点信息。
66
+
67
+ ![](./resources/filetype_txt.png)
68
+
69
+ 2. 获取指定快照 GC Roots 并 console 打印
70
+
71
+ ```bash
72
+ $ ./meminsight ark-stat -t ../files/1.heapsnapshot -m 2 -f console
73
+ | 2025-05-12T09:55:15.421 | [INFO] | meminsight-ArkStatProc: Analyzed successfully.
74
+ | 2025-05-12T09:55:15.422 | [WARN] | meminsight-ArkStatProc: No configuration found, use default config.
75
+ ......
76
+ | 2025-05-12T09:55:15.425 | [INFO] | meminsight-ArkStatProc: Set configuration successfully.
77
+ | 2025-05-12T09:55:15.425 | [INFO] | meminsight-ArkStatProc: mode:2; output:./output; type:console
78
+ {
79
+ FilePath: '../files/1.heapsnapshot',
80
+ 'Action:': 'Get GC Roots',
81
+ NodeLength: 4,
82
+ Time: 1747043715436
83
+ }
84
+ ┌─────────┬────────┬─────────────┬───────────────────────┐
85
+ │ (index) │ id │ type │ name │
86
+ ├─────────┼────────┼─────────────┼───────────────────────┤
87
+ │ 0 │ 1 │ 'synthetic' │ '' │
88
+ │ 1 │ 161260 │ 'native' │ 'InternalNode' │
89
+ │ 2 │ 215678 │ 'native' │ 'InternalNode' │
90
+ │ 3 │ 228378 │ 'native' │ 'PerformanceObserver' │
91
+ └─────────┴────────┴─────────────┴───────────────────────┘
92
+ ```
93
+ 3. 按配置文件获取指定节点,以 json 文件输出
94
+
95
+ 配置文件通过 -c 或 --config 指定文件路径,注意每一类解析器配置文件不同,如 ark-stat 的配置文件参照 ./packages/cfg/ArkStatCfg.json
96
+
97
+ ```bash
98
+ $ ./meminsight ark-stat -t ../files/1.heapsnapshot -m 5 -c ./packages/cfg/ArkStatCfg.json -f json
99
+ | 2025-05-12T10:06:05.337 | [INFO] | meminsight-ArkStatProc: Analyzed successfully.
100
+ ......
101
+ | 2025-05-12T10:06:05.341 | [INFO] | meminsight-ArkStatProc: Set configuration successfully.
102
+ | 2025-05-12T10:06:05.341 | [INFO] | meminsight-ArkStatProc: mode:5; output:./output; type:json
103
+ ```
104
+ 生成的 json 文件只包含按配置文件中定义的过滤器过滤的节点,可以按 json 解析,包含 meta 和 data 两部分。
105
+
106
+ ![](./resources/cfg_filter_filetype_json.png)
107
+
108
+ 4. 获取指定节点的最短引用路径,并 console 打印
109
+
110
+ 5. 获取聚合引用路径信息,并 json 保存
111
+
112
+ 6. 获取共享内存对象信息
113
+
114
+ ### ark-compare(快照比较分析器)
115
+
116
+ ```bash
117
+ $ meminsight ark-compare -h
118
+ Usage: meminsight ark-compare [options]
119
+
120
+ ark compare process.
121
+
122
+ Options:
123
+ -s, --source <file> source heapsnapshot file
124
+ -t, --target <file> target heapsnapshot file
125
+ -n, --node_name <node name>
126
+ -S, --sort_type <sort type: 0 - count | 1 - self_size | 2 - retained_size> sort type (default: 0)
127
+ -c, --config <configuration file> configuration file
128
+ -o, --output <file> output file
129
+ -f, --output_file <file type> output file type, console | text | json | html.
130
+ -h, --help display help for command display help for command
131
+ ```
132
+ ### 示例
133
+
134
+ 1. 比较获取两个快照的差异
135
+
136
+ ```bash
137
+ $ ./meminsight ark-compare -s ../files/3500-1.heapsnapshot -t ../files/3501-1.heapsnapshot -S 0
138
+ ...
139
+ {
140
+ typeName: 'js_weak_ref',
141
+ srcCount: 13707,
142
+ dstCount: 20420,
143
+ countDiff: 6713,
144
+ srcSelfSize: 986904,
145
+ dstSelfSize: 1470240,
146
+ selfSizeDiff: 483336,
147
+ ...
148
+ },
149
+ {
150
+ typeName: 'js_bound_function',
151
+ srcCount: 12147,
152
+ dstCount: 5666,
153
+ countDiff: -6481,
154
+ srcSelfSize: 1360464,
155
+ dstSelfSize: 634592,
156
+ selfSizeDiff: -725872,
157
+ ...
158
+ },
159
+ ...
160
+ ```
161
+
162
+ ### ark-x (统计&聚合分析器)
163
+
164
+ ```bash
165
+ $ ./meminsight ark-x -h
166
+ Usage: meminsight ark-x [options]
167
+
168
+ ark-x analysis process.
169
+
170
+ Options:
171
+ -f, --file <filepath> target filepath (default: "")
172
+ -l, --list <list filepath> one list file which contains snapshot filepathes (default: "")
173
+ -s, --sort <sort tyoe> sort type, 0 - by retained size | 1 - by count (default: 0)
174
+ -T, --top <top number> top number, default is 10 (default: 10)
175
+ -t, --tags <object tags> tobject tags, as tag1,tag2,tag3... (default: "")
176
+ -h, --help display help for command
177
+ ```
178
+
179
+ ### 示例
180
+
181
+ 1. 单个快照统计&聚合
182
+
183
+ ```bash
184
+ $ ./meminsight ark-x --file=../files/1000-1.heapsnapshot
185
+ Heapsnapshot Files:
186
+ /Users/files/1000-1.heapsnapshot
187
+ Start to parse heapsnapshot: /Users/files/1000-1.heapsnapshot
188
+ Success to parse heapsnapshot: /Users/files/1000-1.heapsnapshot
189
+
190
+
191
+ ========================JSObject 对象按 Distance 统计=========================
192
+
193
+ Total Heap Size: 281.53 MB
194
+ Total JSObject Self Size: 19362.06 KB, Ratio: 6.72%
195
+ Total JSObject Retained Size: 142997.51 KB, Ratio: 49.60%
196
+ Total JSObject Count: 316278
197
+ ...
198
+ ```
199
+
200
+ 2. 多个快照统计&聚合
201
+
202
+ - 将多个快照的绝对路径写入一个 list 文本文件,如下
203
+ 建议快照命名格式按 "version-index.heapsnapshot" 命名
204
+ ```
205
+ /Users/files/1000-1.heapsnapshot
206
+ /Users/files/2001-1.heapsnapshot
207
+ ```
208
+
209
+ ```bash
210
+ $ ./meminsight ark-x --list=../files/list.txt
211
+ ...
212
+ Heapsnapshot Files:
213
+ /Users/files/1000-1.heapsnapshot
214
+ /Users/files/2000-1.heapsnapshot
215
+ Start to parse heapsnapshot: /Users/files/1000-1.heapsnapshot
216
+ Success to parse heapsnapshot: /Users/files/2000-1.heapsnapshot
217
+
218
+
219
+ ========================JSObject 对象按 Distance 统计=========================
220
+
221
+ Total Heap Size: 281.53 MB
222
+ Total JSObject Self Size: 19362.06 KB, Ratio: 6.72%
223
+ Total JSObject Retained Size: 142997.51 KB, Ratio: 49.60%
224
+ Total JSObject Count: 316278
225
+ ...
226
+ ```
227
+
228
+ 3. 指定 TopN 统计&聚合
229
+
230
+ ```bash
231
+ $ ./meminsight ark-x --top=5 --file=../files/1000-1.heapsnapshot
232
+ ...
233
+ Info By Count:
234
+ Index-1, ShortestPath: source_text_module_record <- SyntheticRoot,
235
+ Count: 120224,
236
+ Retained Size: 52273.79 KB,
237
+ RetainedSizeTotalHeapPercent: 18.13%,
238
+ Shallow Size: 5966.40 KB,
239
+ ShallowSizeTotalHeapPercent: 2.07%
240
+ Index-2, ShortestPath: JSObject <- JSObject <- SyntheticRoot,
241
+ Count: 78034,
242
+ Retained Size: 5540.46 KB,
243
+ RetainedSizeTotalHeapPercent: 1.92%,
244
+ Shallow Size: 2475.16 KB,
245
+ ShallowSizeTotalHeapPercent: 0.86%
246
+ Index-3, ShortestPath: cow_tagged_array <- class_literal <- constant_pool <- SyntheticRoot,
247
+ Count: 26680,
248
+ Retained Size: 902.73 KB,
249
+ RetainedSizeTotalHeapPercent: 0.31%,
250
+ Shallow Size: 902.73 KB,
251
+ ShallowSizeTotalHeapPercent: 0.31%
252
+ Index-4, ShortestPath: importentry_record <- tagged_array <- source_text_module_record <- SyntheticRoot,
253
+ Count: 25133,
254
+ Retained Size: 824.41 KB,
255
+ RetainedSizeTotalHeapPercent: 0.29%,
256
+ Shallow Size: 824.41 KB,
257
+ ShallowSizeTotalHeapPercent: 0.29%
258
+ Index-5, ShortestPath: tagged_dictionary <- JSObject <- constant_pool <- SyntheticRoot,
259
+ Count: 24564,
260
+ Retained Size: 603.82 KB,
261
+ RetainedSizeTotalHeapPercent: 0.21%,
262
+ Shallow Size: 603.82 KB,
263
+ ShallowSizeTotalHeapPercent: 0.21%
264
+ ...
265
+ ```
266
+
267
+ 4. 指定排序方式获取TopN的统计&聚合(按大小排序/按个数排序)
268
+
269
+ 通过 --sort 来设置排序方式
270
+
271
+ ```bash
272
+ -s, --sort <sort tyoe> sort type, 0 - by retained size | 1 - by count (default: 0)
273
+ ```
274
+
275
+ ```bash
276
+ # 按大小排序
277
+ $ ./meminsight ark-x --top=5 --file=../files/1000-1.heapsnapshot --sort=1
278
+ ...
279
+ Info By Count:
280
+ Index-1, ShortestPath: source_text_module_record <- SyntheticRoot,
281
+ Count: 120224,
282
+ Retained Size: 52273.79 KB,
283
+ RetainedSizeTotalHeapPercent: 18.13%,
284
+ Shallow Size: 5966.40 KB,
285
+ ShallowSizeTotalHeapPercent: 2.07%
286
+ Index-2, ShortestPath: JSObject <- JSObject <- SyntheticRoot,
287
+ Count: 78034,
288
+ Retained Size: 5540.46 KB,
289
+ RetainedSizeTotalHeapPercent: 1.92%,
290
+ Shallow Size: 2475.16 KB,
291
+ ShallowSizeTotalHeapPercent: 0.86%
292
+ Index-3, ShortestPath: cow_tagged_array <- class_literal <- constant_pool <- SyntheticRoot,
293
+ Count: 26680,
294
+ Retained Size: 902.73 KB,
295
+ RetainedSizeTotalHeapPercent: 0.31%,
296
+ Shallow Size: 902.73 KB,
297
+ ShallowSizeTotalHeapPercent: 0.31%
298
+ Index-4, ShortestPath: importentry_record <- tagged_array <- source_text_module_record <- SyntheticRoot,
299
+ Count: 25133,
300
+ Retained Size: 824.41 KB,
301
+ RetainedSizeTotalHeapPercent: 0.29%,
302
+ Shallow Size: 824.41 KB,
303
+ ShallowSizeTotalHeapPercent: 0.29%
304
+ Index-5, ShortestPath: tagged_dictionary <- JSObject <- constant_pool <- SyntheticRoot,
305
+ Count: 24564,
306
+ Retained Size: 603.82 KB,
307
+ RetainedSizeTotalHeapPercent: 0.21%,
308
+ Shallow Size: 603.82 KB,
309
+ ShallowSizeTotalHeapPercent: 0.21%
310
+ ...
311
+ ```
312
+
313
+ 5. 类名中包含指定标签的统计&聚合
314
+
315
+ - 通过 --tags 设置标签
316
+ - 多个标签通过 “,” 分隔,如 “--tags=tag1,tag2,tag3”
317
+
318
+ ```bash
319
+ $ ./meminsight ark-x --file=../files/1000-1.heapsnapshot --tags=tag1,tag2
320
+
321
+ ...
322
+ ```
323
+
324
+ ## npm 包
325
+
326
+ ### analyzer
327
+
328
+ [](./resources/analyzer.png)
329
+
330
+ ### 接口说明
331
+
332
+ 参见文档 [Interface](./Interface.md)
Binary file
Binary file
Binary file
Binary file
Binary file