• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <hwext/gtest-ext.h>
17 #include <hwext/gtest-tag.h>
18 #include <fcntl.h>
19 #include <fstream>
20 #include <iostream>
21 #include <string>
22 #include <unistd.h>
23 
24 #include "file.h"
25 #include "arkts/pbreader_js_memory_parser.h"
26 #include "js_heap_config.pb.h"
27 #include "js_heap_config.pbreader.h"
28 #include "js_heap_result.pb.h"
29 #include "js_heap_result.pbreader.h"
30 #include "trace_streamer_selector.h"
31 
32 using namespace testing::ext;
33 using namespace SysTuning;
34 using namespace SysTuning::TraceStreamer;
35 namespace SysTuning {
36 namespace TraceStreamer {
37 class JsMemoryTest : public ::testing::Test {
38 public:
SetUp()39     void SetUp()
40     {
41         stream_.InitFilter();
42     }
43 
TearDown()44     void TearDown() {}
45 
SerializeConfig(ArkTSConfig_HeapType type)46     void SerializeConfig(ArkTSConfig_HeapType type)
47     {
48         const int32_t pid = 1734;
49         ArkTSConfig arkTSConfig;
50         arkTSConfig.set_pid(pid);
51         arkTSConfig.set_type(type);
52         arkTSConfig.SerializeToString(&strConfig_);
53     }
54 
SerializeResult(std::vector<std::string> & strResultVec,std::vector<std::string> & resultVec)55     void SerializeResult(std::vector<std::string> &strResultVec, std::vector<std::string> &resultVec)
56     {
57         ArkTSResult jsHeapResult;
58         for (int i = 0; i < resultVec.size(); i++) {
59             jsHeapResult.set_result(resultVec[i]);
60             std::string strResult = "";
61             jsHeapResult.SerializeToString(&strResult);
62             strResultVec.push_back(strResult);
63         }
64     }
65 
SetSnapshotParserNodesByJsmemory(std::vector<std::string> & strResultVec)66     void SetSnapshotParserNodesByJsmemory(std::vector<std::string> &strResultVec)
67     {
68         std::string result1 =
69             "{\"method\":\"HeapProfiler.reportHeapSnapshotProgress\",\"params\":{\"done\":0,\"total\":21288}}";
70         std::string result2 =
71             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
72             "\\\"meta\\\":"
73             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
74             "\\\"trace_"
75             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
76             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
77             "\\\"synthetic\\\","
78             "\\\"concatenated "
79             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
80             "\\\"number\\\","
81             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
82             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
83             "\\\"internal\\\","
84             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
85             "function_"
86             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
87             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
88             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
89             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
90             "\\n\\\"node_"
91             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
92             "25571,"
93             "1,0,3575,0,0\\n,1,3,3,432,52,0,0\\n,8,9,9949,40,\"}}";
94         std::string result3 =
95             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[],"
96             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[],"
97             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
98         std::string result4 = "{\"id\":1,\"result\":{}}";
99         std::vector<std::string> resultVec = {result1, result2, result3, result4};
100         SerializeResult(strResultVec, resultVec);
101     }
102 
SetSnapshotParserEdgesByJsmemory(std::vector<std::string> & strResultVec)103     void SetSnapshotParserEdgesByJsmemory(std::vector<std::string> &strResultVec)
104     {
105         std::string result1 =
106             "{\"method\":\"HeapProfiler.reportHeapSnapshotProgress\",\"params\":{\"done\":0,\"total\":21288}}";
107         std::string result2 =
108             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
109             "\\\"meta\\\":"
110             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
111             "\\\"trace_"
112             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
113             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
114             "\\\"synthetic\\\","
115             "\\\"concatenated "
116             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
117             "\\\"number\\\","
118             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
119             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
120             "\\\"internal\\\","
121             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
122             "function_"
123             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
124             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
125             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
126             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
127             "\\n\\\"node_"
128             "count\\\":3,\\n\\\"edge_count\\\":5,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,25571,"
129             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
130         std::string result3 =
131             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
132             "25572,"
133             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
134             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[],"
135             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
136         std::string result4 = "{\"id\":1,\"result\":{}}";
137         std::vector<std::string> resultVec = {result1, result2, result3, result4};
138         SerializeResult(strResultVec, resultVec);
139     }
140 
SetTimelineParserNodesByJsmemory(std::vector<std::string> & strResultVec)141     void SetTimelineParserNodesByJsmemory(std::vector<std::string> &strResultVec)
142     {
143         std::string result1 = "{\"id\":1,\"result\":{}}";
144         std::string result2 =
145             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
146             "\\\"meta\\\":"
147             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
148             "\\\"trace_"
149             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
150             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
151             "\\\"synthetic\\\","
152             "\\\"concatenated "
153             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
154             "\\\"number\\\","
155             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
156             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
157             "\\\"internal\\\","
158             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
159             "function_"
160             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
161             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
162             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
163             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
164             "\\n\\\"node_"
165             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
166             "25571,"
167             "1,0,3575,0,0\\n,1,3,3,432,52,0,0\\n,8,9,9949,40,\"}}";
168         std::string result3 =
169             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[],"
170             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[],"
171             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
172         std::string result4 = "{\"id\":2,\"result\":{}}";
173         std::vector<std::string> resultVec = {result1, result2, result3, result4};
174         SerializeResult(strResultVec, resultVec);
175     }
176 
SetTimelineParserEdgesByJsmemory(std::vector<std::string> & strResultVec)177     void SetTimelineParserEdgesByJsmemory(std::vector<std::string> &strResultVec)
178     {
179         std::string result1 = "{\"id\":1,\"result\":{}}";
180         std::string result2 =
181             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
182             "\\\"meta\\\":"
183             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
184             "\\\"trace_"
185             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
186             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
187             "\\\"synthetic\\\","
188             "\\\"concatenated "
189             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
190             "\\\"number\\\","
191             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
192             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
193             "\\\"internal\\\","
194             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
195             "function_"
196             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
197             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
198             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
199             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
200             "\\n\\\"node_"
201             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
202             "25571,"
203             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
204         std::string result3 =
205             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
206             "25572,"
207             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
208             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[],"
209             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
210         std::string result4 = "{\"id\":2,\"result\":{}}";
211         std::vector<std::string> resultVec = {result1, result2, result3, result4};
212         SerializeResult(strResultVec, resultVec);
213     }
214 
SetTimelineParserSamplesByJsmemory(std::vector<std::string> & strResultVec)215     void SetTimelineParserSamplesByJsmemory(std::vector<std::string> &strResultVec)
216     {
217         std::string result1 = "{\"id\":1,\"result\":{}}";
218         std::string result2 =
219             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
220             "\\\"meta\\\":"
221             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
222             "\\\"trace_"
223             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
224             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
225             "\\\"synthetic\\\","
226             "\\\"concatenated "
227             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
228             "\\\"number\\\","
229             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
230             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
231             "\\\"internal\\\","
232             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
233             "function_"
234             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
235             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
236             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
237             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
238             "\\n\\\"node_"
239             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
240             "25571,"
241             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
242         std::string result3 =
243             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
244             "25572,"
245             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
246             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[0, 42570\\n, 200631, 42571\\n, 401040, 42572\\n, 601899, "
247             "42573\\n, 804764, 42574\\n, 1006866, 42575\\n, 1207797, "
248             "42576\\n],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[],"
249             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
250         std::string result4 = "{\"id\":2,\"result\":{}}";
251         std::vector<std::string> resultVec = {result1, result2, result3, result4};
252         SerializeResult(strResultVec, resultVec);
253     }
254 
SetTimelineParserStringsByJsmemory(std::vector<std::string> & strResultVec)255     void SetTimelineParserStringsByJsmemory(std::vector<std::string> &strResultVec)
256     {
257         std::string result1 = "{\"id\":1,\"result\":{}}";
258         std::string result2 =
259             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
260             "\\\"meta\\\":"
261             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
262             "\\\"trace_"
263             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
264             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
265             "\\\"synthetic\\\","
266             "\\\"concatenated "
267             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
268             "\\\"number\\\","
269             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
270             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
271             "\\\"internal\\\","
272             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
273             "function_"
274             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
275             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
276             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
277             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
278             "\\n\\\"node_"
279             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
280             "25571,"
281             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
282         std::string result3 =
283             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
284             "25572,"
285             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
286             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[0, 42570\\n, 200631, 42571\\n, 401040, 42572\\n, 601899, "
287             "42573\\n, 804764, 42574\\n, 1006866, 42575\\n, 1207797, "
288             "42576\\n],\\n\\\"strings\\\":[\\\"<dummy>\\\",\\n\\\"\\\",\\n\\\"GC "
289             "roots\\\",\\n\\\"TaggedDict[52]\\\",\\n\\\"JSFunction\\\"],\\n\\\"trace_function_infos\\\":[],"
290             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
291         std::string result4 = "{\"id\":2,\"result\":{}}";
292         std::vector<std::string> resultVec = {result1, result2, result3, result4};
293         SerializeResult(strResultVec, resultVec);
294     }
295 
SetTimelineParserTraceFuncInfoByJsmemory(std::vector<std::string> & strResultVec)296     void SetTimelineParserTraceFuncInfoByJsmemory(std::vector<std::string> &strResultVec)
297     {
298         std::string result1 = "{\"id\":1,\"result\":{}}";
299         std::string result2 =
300             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
301             "\\\"meta\\\":"
302             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
303             "\\\"trace_"
304             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
305             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
306             "\\\"synthetic\\\","
307             "\\\"concatenated "
308             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
309             "\\\"number\\\","
310             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
311             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
312             "\\\"internal\\\","
313             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
314             "function_"
315             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
316             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
317             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
318             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
319             "\\n\\\"node_"
320             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
321             "25571,"
322             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
323         std::string result3 =
324             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
325             "25572,"
326             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
327             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[0,"
328             "181,"
329             "1601,0,0,"
330             "0\\n],"
331             "\\n\\\"trace_tree\\\":[]}\\n\"}}";
332         std::string result4 = "{\"id\":2,\"result\":{}}";
333         std::vector<std::string> resultVec = {result1, result2, result3, result4};
334         SerializeResult(strResultVec, resultVec);
335     }
336 
SetTimelineParserTraceTreeByJsmemory(std::vector<std::string> & strResultVec)337     void SetTimelineParserTraceTreeByJsmemory(std::vector<std::string> &strResultVec)
338     {
339         std::string result1 = "{\"id\":1,\"result\":{}}";
340         std::string result2 =
341             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"{\\\"snapshot\\\":\\n{"
342             "\\\"meta\\\":"
343             "\\n{\\\"node_fields\\\":[\\\"type\\\",\\\"name\\\",\\\"id\\\",\\\"self_size\\\",\\\"edge_count\\\","
344             "\\\"trace_"
345             "node_id\\\",\\\"detachedness\\\"],\\n\\\"node_types\\\":[[\\\"hidden\\\",\\\"array\\\",\\\"string\\\","
346             "\\\"object\\\",\\\"code\\\",\\\"closure\\\",\\\"regexp\\\",\\\"number\\\",\\\"native\\\","
347             "\\\"synthetic\\\","
348             "\\\"concatenated "
349             "string\\\",\\\"slicedstring\\\",\\\"symbol\\\",\\\"bigint\\\"],\\\"string\\\",\\\"number\\\","
350             "\\\"number\\\","
351             "\\\"number\\\",\\\"number\\\",\\\"number\\\"],\\n\\\"edge_fields\\\":[\\\"type\\\",\\\"name_or_index\\\","
352             "\\\"to_node\\\"],\\n\\\"edge_types\\\":[[\\\"context\\\",\\\"element\\\",\\\"property\\\","
353             "\\\"internal\\\","
354             "\\\"hidden\\\",\\\"shortcut\\\",\\\"weak\\\"],\\\"string_or_number\\\",\\\"node\\\"],\\n\\\"trace_"
355             "function_"
356             "info_fields\\\":[\\\"function_id\\\",\\\"name\\\",\\\"script_name\\\",\\\"script_id\\\",\\\"line\\\","
357             "\\\"column\\\"],\\n\\\"trace_node_fields\\\":[\\\"id\\\",\\\"function_info_index\\\",\\\"count\\\","
358             "\\\"size\\\",\\\"children\\\"],\\n\\\"sample_fields\\\":[\\\"timestamp_us\\\",\\\"last_assigned_id\\\"],"
359             "\\n\\\"location_fields\\\":[\\\"object_index\\\",\\\"script_id\\\",\\\"line\\\",\\\"column\\\"]},"
360             "\\n\\\"node_"
361             "count\\\":32837,\\n\\\"edge_count\\\":152856,\\n\\\"trace_function_count\\\":0\\n},\\n\\\"nodes\\\":[9,"
362             "25571,"
363             "1,0,1,0,0\\n,1,3,3,432,3,0,0\\n,8,9,9949,40,\"}}";
364         std::string result3 =
365             "{\"method\":\"HeapProfiler.addHeapSnapshotChunk\",\"params\":{\"chunk\":\"1,0,0],\\n\\\"edges\\\":[5,"
366             "25572,"
367             "1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n,5,25572,1\\n],"
368             "\\n\\\"locations\\\":[],\\n\\\"samples\\\":[],\\n\\\"strings\\\":[],\\n\\\"trace_function_infos\\\":[0,"
369             "181,"
370             "1601,0,0,"
371             "0\\n],"
372             "\\n\\\"trace_tree\\\":[1,0,53,996,[2,1,571,26580,[],3,2,5,248,[4,3,27,2684,[5,4,1352,68984,[6,5,20,920,[]]"
373             ",7,"
374             "6,5,144,[],8,7,18,636,[9,8,5,120,[10,9,1,28,[]]]]],11,10,10,348,[12,11,11,576,[13,12,21,632,[14,14,0,0,["
375             "15,13,"
376             "2,28,[]],16,15,5,188,[17,16,7,196,[]]]]],18,17,10,560,[19,9,2,28,[],20,18,172,7896,[21,19,4,3196,[]]]]]}"
377             "\\n\"}"
378             "}";
379         std::string result4 = "{\"id\":2,\"result\":{}}";
380         std::vector<std::string> resultVec = {result1, result2, result3, result4};
381         SerializeResult(strResultVec, resultVec);
382     }
383 
384 public:
385     SysTuning::TraceStreamer::TraceStreamerSelector stream_ = {};
386     std::string strConfig_ = "";
387 };
388 /**
389  * @tc.name: snapshotParserNodesbyJsmemory
390  * @tc.desc: snapshot parser nodes
391  * @tc.type: FUNC
392  */
393 HWTEST_F(JsMemoryTest, snapshotParserNodesByJsmemory, TestSize.Level1)
394 {
395     TS_LOGI("test35-1");
396     SerializeConfig(ArkTSConfig_HeapType(0));
397     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
398     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
399     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
400 
401     std::vector<std::string> strResultVec;
402     SetSnapshotParserNodesByJsmemory(strResultVec);
403     ASSERT_EQ(4, strResultVec.size());
404     std::string strResult1 = strResultVec[0];
405     std::string strResult2 = strResultVec[1];
406     std::string strResult3 = strResultVec[2];
407     std::string strResult4 = strResultVec[3];
408     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
409     ProfilerPluginDataHeader profilerPluginData;
410     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
411 
412     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
413     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
414 
415     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
416     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
417 
418     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
419     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
420     htraceJSMemoryParser.Finish();
421 
422     auto jsHeapFilesData = stream_.traceDataCache_->GetConstJsHeapFilesData();
423     ASSERT_EQ(1, jsHeapFilesData.Size());
424     EXPECT_EQ("Snapshot0", jsHeapFilesData.FilePaths()[0]);
425     EXPECT_EQ(11000, jsHeapFilesData.StartTimes()[0]);
426     EXPECT_EQ(13000, jsHeapFilesData.EndTimes()[0]);
427     auto jsHeapNodesData = stream_.traceDataCache_->GetConstJsHeapNodesData();
428     EXPECT_EQ(9, jsHeapNodesData.Types()[0]);
429     EXPECT_EQ(25571, jsHeapNodesData.Names()[0]);
430     EXPECT_EQ(1, jsHeapNodesData.NodeIds()[0]);
431     EXPECT_EQ(0, jsHeapNodesData.SelfSizes()[0]);
432     EXPECT_EQ(3575, jsHeapNodesData.EdgeCounts()[0]);
433     EXPECT_EQ(0, jsHeapNodesData.TraceNodeIds()[0]);
434     EXPECT_EQ(0, jsHeapNodesData.DetachedNess()[0]);
435 }
436 
437 HWTEST_F(JsMemoryTest, snapshotParserEdgesByJsmemory, TestSize.Level1)
438 {
439     TS_LOGI("test35-2");
440     SerializeConfig(ArkTSConfig_HeapType(0));
441     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
442     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
443     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
444 
445     std::vector<std::string> strResultVec;
446     SetSnapshotParserEdgesByJsmemory(strResultVec);
447     std::string strResult1 = strResultVec[0];
448     std::string strResult2 = strResultVec[1];
449     std::string strResult3 = strResultVec[2];
450     std::string strResult4 = strResultVec[3];
451     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
452     ProfilerPluginDataHeader profilerPluginData;
453     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
454 
455     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
456     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
457 
458     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
459     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
460 
461     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
462     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
463     htraceJSMemoryParser.Finish();
464 
465     auto jsHeapEdgesData = stream_.traceDataCache_->GetConstJsHeapEdgesData();
466     EXPECT_EQ(5, jsHeapEdgesData.Types()[0]);
467     EXPECT_EQ(25572, jsHeapEdgesData.NameOrIndexs()[0]);
468     EXPECT_EQ(1, jsHeapEdgesData.ToNodes()[0]);
469     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[0]);
470     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[1]);
471     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[2]);
472     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[3]);
473     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[4]);
474 }
475 
476 HWTEST_F(JsMemoryTest, timelineParserNodesByJsmemory, TestSize.Level1)
477 {
478     TS_LOGI("test35-3");
479     SerializeConfig(ArkTSConfig_HeapType(1));
480     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
481     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
482     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
483 
484     std::vector<std::string> strResultVec;
485     SetTimelineParserNodesByJsmemory(strResultVec);
486     std::string strResult1 = strResultVec[0];
487     std::string strResult2 = strResultVec[1];
488     std::string strResult3 = strResultVec[2];
489     std::string strResult4 = strResultVec[3];
490     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
491     ProfilerPluginDataHeader profilerPluginData;
492     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
493 
494     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
495     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
496 
497     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
498     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
499 
500     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
501     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
502     htraceJSMemoryParser.Finish();
503 
504     auto jsHeapFilesData = stream_.traceDataCache_->GetConstJsHeapFilesData();
505     ASSERT_EQ(1, jsHeapFilesData.Size());
506     EXPECT_EQ("Timeline", jsHeapFilesData.FilePaths()[0]);
507     EXPECT_EQ(10000, jsHeapFilesData.StartTimes()[0]);
508     EXPECT_EQ(13000, jsHeapFilesData.EndTimes()[0]);
509     auto jsHeapNodesData = stream_.traceDataCache_->GetConstJsHeapNodesData();
510     EXPECT_EQ(9, jsHeapNodesData.Types()[0]);
511     EXPECT_EQ(25571, jsHeapNodesData.Names()[0]);
512     EXPECT_EQ(1, jsHeapNodesData.NodeIds()[0]);
513     EXPECT_EQ(0, jsHeapNodesData.SelfSizes()[0]);
514     EXPECT_EQ(3575, jsHeapNodesData.EdgeCounts()[0]);
515     EXPECT_EQ(0, jsHeapNodesData.TraceNodeIds()[0]);
516     EXPECT_EQ(0, jsHeapNodesData.DetachedNess()[0]);
517 }
518 
519 HWTEST_F(JsMemoryTest, timelineParserEdgesByJsmemory, TestSize.Level1)
520 {
521     TS_LOGI("test35-4");
522     SerializeConfig(ArkTSConfig_HeapType(1));
523     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
524     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
525     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
526 
527     std::vector<std::string> strResultVec;
528     SetTimelineParserEdgesByJsmemory(strResultVec);
529     std::string strResult1 = strResultVec[0];
530     std::string strResult2 = strResultVec[1];
531     std::string strResult3 = strResultVec[2];
532     std::string strResult4 = strResultVec[3];
533     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
534     ProfilerPluginDataHeader profilerPluginData;
535     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
536 
537     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
538     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
539 
540     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
541     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
542 
543     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
544     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
545     htraceJSMemoryParser.Finish();
546 
547     auto jsHeapEdgesData = stream_.traceDataCache_->GetConstJsHeapEdgesData();
548     EXPECT_EQ(5, jsHeapEdgesData.Types()[0]);
549     EXPECT_EQ(25572, jsHeapEdgesData.NameOrIndexs()[0]);
550     EXPECT_EQ(1, jsHeapEdgesData.ToNodes()[0]);
551     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[0]);
552     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[1]);
553     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[2]);
554     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[3]);
555     EXPECT_EQ(1, jsHeapEdgesData.FromNodeIds()[4]);
556 }
557 
558 HWTEST_F(JsMemoryTest, timelineParserSamplesByJsmemory, TestSize.Level1)
559 {
560     TS_LOGI("test35-5");
561     SerializeConfig(ArkTSConfig_HeapType(1));
562     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
563     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
564     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
565 
566     std::vector<std::string> strResultVec;
567     SetTimelineParserSamplesByJsmemory(strResultVec);
568     std::string strResult1 = strResultVec[0];
569     std::string strResult2 = strResultVec[1];
570     std::string strResult3 = strResultVec[2];
571     std::string strResult4 = strResultVec[3];
572     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
573     ProfilerPluginDataHeader profilerPluginData;
574     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
575 
576     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
577     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
578 
579     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
580     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
581 
582     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
583     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
584     htraceJSMemoryParser.Finish();
585 
586     auto jsHeapSampleData = stream_.traceDataCache_->GetConstJsHeapSampleData();
587     EXPECT_EQ(0, jsHeapSampleData.TimeStampUs()[0]);
588     EXPECT_EQ(42570, jsHeapSampleData.LastAssignedIds()[0]);
589     EXPECT_EQ(200631, jsHeapSampleData.TimeStampUs()[1]);
590     EXPECT_EQ(42571, jsHeapSampleData.LastAssignedIds()[1]);
591     EXPECT_EQ(401040, jsHeapSampleData.TimeStampUs()[2]);
592     EXPECT_EQ(42572, jsHeapSampleData.LastAssignedIds()[2]);
593     EXPECT_EQ(601899, jsHeapSampleData.TimeStampUs()[3]);
594     EXPECT_EQ(42573, jsHeapSampleData.LastAssignedIds()[3]);
595 }
596 
597 HWTEST_F(JsMemoryTest, timelineParserStringsByJsmemory, TestSize.Level1)
598 {
599     TS_LOGI("test35-6");
600     SerializeConfig(ArkTSConfig_HeapType(1));
601     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
602     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
603     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
604 
605     std::vector<std::string> strResultVec;
606     SetTimelineParserStringsByJsmemory(strResultVec);
607     std::string strResult1 = strResultVec[0];
608     std::string strResult2 = strResultVec[1];
609     std::string strResult3 = strResultVec[2];
610     std::string strResult4 = strResultVec[3];
611     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
612     ProfilerPluginDataHeader profilerPluginData;
613     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
614 
615     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
616     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
617 
618     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
619     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
620 
621     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
622     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
623     htraceJSMemoryParser.Finish();
624 
625     auto jsHeapStringData = stream_.traceDataCache_->GetConstJsHeapStringData();
626     EXPECT_EQ("<dummy>", jsHeapStringData.Strings()[0]);
627     EXPECT_EQ("", jsHeapStringData.Strings()[1]);
628     EXPECT_EQ("GC roots", jsHeapStringData.Strings()[2]);
629     EXPECT_EQ("TaggedDict[52]", jsHeapStringData.Strings()[3]);
630     EXPECT_EQ("JSFunction", jsHeapStringData.Strings()[4]);
631 }
632 
633 HWTEST_F(JsMemoryTest, timelineParserTraceFuncInfoByJsmemory, TestSize.Level1)
634 {
635     TS_LOGI("test35-7");
636     SerializeConfig(ArkTSConfig_HeapType(1));
637     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
638     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
639     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
640 
641     std::vector<std::string> strResultVec;
642     SetTimelineParserTraceFuncInfoByJsmemory(strResultVec);
643     std::string strResult1 = strResultVec[0];
644     std::string strResult2 = strResultVec[1];
645     std::string strResult3 = strResultVec[2];
646     std::string strResult4 = strResultVec[3];
647     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
648     ProfilerPluginDataHeader profilerPluginData;
649     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
650 
651     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
652     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
653 
654     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
655     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
656 
657     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
658     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
659     htraceJSMemoryParser.Finish();
660 
661     auto jsHeapTraceFuncInfoData = stream_.traceDataCache_->GetConstJsHeapTraceFuncInfoData();
662     EXPECT_EQ(0, jsHeapTraceFuncInfoData.FunctionIds()[0]);
663     EXPECT_EQ(181, jsHeapTraceFuncInfoData.Names()[0]);
664     EXPECT_EQ(1601, jsHeapTraceFuncInfoData.ScriptNames()[0]);
665     EXPECT_EQ(0, jsHeapTraceFuncInfoData.ScriptIds()[0]);
666     EXPECT_EQ(0, jsHeapTraceFuncInfoData.Lines()[0]);
667     EXPECT_EQ(0, jsHeapTraceFuncInfoData.Columns()[0]);
668 }
669 
670 HWTEST_F(JsMemoryTest, timelineParserTraceTreeByJsmemory, TestSize.Level1)
671 {
672     TS_LOGI("test35-8");
673     SerializeConfig(ArkTSConfig_HeapType(1));
674     PbreaderJSMemoryParser htraceJSMemoryParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
675     ProtoReader::BytesView tracePacket(reinterpret_cast<const uint8_t *>(strConfig_.data()), strConfig_.size());
676     htraceJSMemoryParser.ParseJSMemoryConfig(tracePacket);
677 
678     std::vector<std::string> strResultVec;
679     SetTimelineParserTraceTreeByJsmemory(strResultVec);
680     std::string strResult1 = strResultVec[0];
681     std::string strResult2 = strResultVec[1];
682     std::string strResult3 = strResultVec[2];
683     std::string strResult4 = strResultVec[3];
684     ProtoReader::BytesView tracePacket1(reinterpret_cast<const uint8_t *>(strResult1.data()), strResult1.size());
685     ProfilerPluginDataHeader profilerPluginData;
686     htraceJSMemoryParser.Parse(tracePacket1, 10000, 0, 0, profilerPluginData);
687 
688     ProtoReader::BytesView tracePacket2(reinterpret_cast<const uint8_t *>(strResult2.data()), strResult2.size());
689     htraceJSMemoryParser.Parse(tracePacket2, 11000, 0, 0, profilerPluginData);
690 
691     ProtoReader::BytesView tracePacket3(reinterpret_cast<const uint8_t *>(strResult3.data()), strResult3.size());
692     htraceJSMemoryParser.Parse(tracePacket3, 12000, 0, 0, profilerPluginData);
693 
694     ProtoReader::BytesView tracePacket4(reinterpret_cast<const uint8_t *>(strResult4.data()), strResult4.size());
695     htraceJSMemoryParser.Parse(tracePacket4, 13000, 0, 0, profilerPluginData);
696     htraceJSMemoryParser.Finish();
697 
698     auto jsHeapTraceNodeData = stream_.traceDataCache_->GetConstJsHeapTraceNodeData();
699     EXPECT_EQ(0, jsHeapTraceNodeData.FunctionInfoIndexs()[0]);
700     EXPECT_EQ(53, jsHeapTraceNodeData.Counts()[0]);
701     EXPECT_EQ(996, jsHeapTraceNodeData.NodeSizes()[0]);
702     EXPECT_EQ(-1, jsHeapTraceNodeData.ParentIds()[0]);
703     EXPECT_EQ(1, jsHeapTraceNodeData.FunctionInfoIndexs()[1]);
704     EXPECT_EQ(571, jsHeapTraceNodeData.Counts()[1]);
705     EXPECT_EQ(26580, jsHeapTraceNodeData.NodeSizes()[1]);
706     EXPECT_EQ(1, jsHeapTraceNodeData.ParentIds()[1]);
707     EXPECT_EQ(2, jsHeapTraceNodeData.FunctionInfoIndexs()[2]);
708     EXPECT_EQ(5, jsHeapTraceNodeData.Counts()[2]);
709     EXPECT_EQ(248, jsHeapTraceNodeData.NodeSizes()[2]);
710     EXPECT_EQ(1, jsHeapTraceNodeData.ParentIds()[2]);
711     EXPECT_EQ(3, jsHeapTraceNodeData.ParentIds()[3]);
712     EXPECT_EQ(4, jsHeapTraceNodeData.ParentIds()[4]);
713     EXPECT_EQ(10, jsHeapTraceNodeData.FunctionInfoIndexs()[10]);
714     EXPECT_EQ(10, jsHeapTraceNodeData.Counts()[10]);
715     EXPECT_EQ(348, jsHeapTraceNodeData.NodeSizes()[10]);
716     EXPECT_EQ(1, jsHeapTraceNodeData.ParentIds()[10]);
717 }
718 } // namespace TraceStreamer
719 } // namespace SysTuning
720