• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
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
16import { SpProcessChart } from '../../../../src/trace/component/chart/SpProcessChart';
17const sqlit = require('../../../../src/trace/database/SqlLite');
18jest.mock('../../../../src/trace/database/SqlLite');
19
20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
21  return {};
22});
23
24const intersectionObserverMock = () => ({
25  observe: () => null,
26});
27window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
28import { SpSystemTrace } from "../../../../src/trace/component/SpSystemTrace";
29// @ts-ignore
30window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({
31  observe: jest.fn(),
32  unobserve: jest.fn(),
33  disconnect: jest.fn(),
34}));
35
36describe('SpProcessChart Test', () => {
37  let manager = new SpSystemTrace();
38  let spProcessChart = new SpProcessChart(manager);
39  let MockqueryProcessAsyncFunc = sqlit.queryProcessAsyncFunc;
40
41  MockqueryProcessAsyncFunc.mockResolvedValue([
42    {
43      tid: 1,
44      pid: 1,
45      threadName: '1',
46      track_id: 3,
47      startTs: 1111,
48      dur: 2000000,
49      funName: 'deliverInputEvent',
50      parent_id: 4,
51      id: 5,
52      cookie: 'ff',
53      depth: 5,
54      argsetid: 6,
55    },
56  ]);
57  let processContentCount = sqlit.queryProcessContentCount;
58  processContentCount.mockResolvedValue([
59    {
60      pid: 1,
61      switch_count: 2,
62      thread_count: 3,
63      slice_count: 4,
64      mem_count: 5,
65    },
66  ]);
67  let queryProcessThreads = sqlit.queryProcessThreads;
68  queryProcessThreads.mockResolvedValue([]);
69  let queryProcessThreadsByTable = sqlit.queryProcessThreadsByTable;
70  queryProcessThreadsByTable.mockResolvedValue([
71    {
72      pid: 1,
73      tid: 0,
74      processName: 'process',
75      threadName: 'thread',
76    },
77  ]);
78  let queryProcessMem = sqlit.queryProcessMem;
79  queryProcessMem.mockResolvedValue([
80    {
81      trackId: 1,
82      trackName: 'trackName',
83      upid: 2,
84      pid: 1,
85      processName: 'processName',
86    },
87  ]);
88  let queryEventCountMap = sqlit.queryEventCountMap;
89  queryEventCountMap.mockResolvedValue([
90    {
91      eventName: 'eventName',
92      count: 1,
93    },
94  ]);
95  let queryProcess = sqlit.queryProcess;
96  queryProcess.mockResolvedValue([
97    {
98      pid: 1,
99      processName: 'processName',
100    },
101  ]);
102
103  let queryProcessByTable = sqlit.queryProcessByTable;
104  queryProcessByTable.mockResolvedValue([
105    {
106      pid: 2,
107      processName: 'processName',
108    },
109  ]);
110
111  let getMaxDepthByTid = sqlit.getMaxDepthByTid;
112  getMaxDepthByTid.mockResolvedValue([
113    {
114      tid: 1,
115      maxDepth: 1,
116    },
117    {
118      tid: 2,
119      maxDepth: 2,
120    },
121  ]);
122  let queryAllJankProcess = sqlit.queryAllJankProcess;
123  queryAllJankProcess.mockResolvedValue([
124    {
125      pid: 1,
126    },
127  ]);
128
129  let queryAllExpectedData = sqlit.queryAllExpectedData;
130  queryAllExpectedData.mockResolvedValue([
131    {
132      id: 41,
133      ts: 749660047,
134      name: 1159,
135      type: 1,
136      dur: 16657682,
137      pid: 1242,
138      cmdline: 'render_service',
139    },
140    {
141      id: 45,
142      ts: 766321174,
143      name: 1160,
144      type: 1,
145      dur: 16657682,
146      pid: 1,
147      cmdline: 'render_service',
148    },
149  ]);
150
151  let queryAllActualData = sqlit.queryAllActualData;
152  queryAllActualData.mockResolvedValue([
153    {
154      id: 40,
155      ts: 750328000,
156      name: 1159,
157      type: 0,
158      dur: 22925000,
159      src_slice: '36',
160      jank_tag: 1,
161      dst_slice: null,
162      pid: 1242,
163      cmdline: 'render_service',
164      frame_type: 'render_service',
165    },
166    {
167      id: 44,
168      ts: 773315000,
169      name: 1160,
170      type: 0,
171      dur: 17740000,
172      src_slice: '38,42',
173      jank_tag: 1,
174      dst_slice: null,
175      pid: 1,
176      cmdline: 'render_service',
177      frame_type: 'render_service',
178    },
179  ]);
180
181  let queryProcessStartup = sqlit.queryProcessStartup;
182  queryProcessStartup.mockResolvedValue([
183    {
184      'pid': 3913,
185      'tid': 3913,
186      'itid': 366,
187      'startTs': 5651745832,
188      'dur': 38654167,
189      'startName': 0,
190      'endItid': 341,
191      'frame': {
192        'y': 5,
193        'height': 20,
194        'x': 1154,
195        'width': 9
196      },
197      'v': true,
198      'stepName': 'Process Creating (38.65ms)',
199      'textMetricsWidth': 129.072265625
200    },
201    {
202      'pid': 3913,
203      'tid': 3913,
204      'itid': 341,
205      'startTs': 5690399999,
206      'dur': 43619792,
207      'startName': 1,
208      'endItid': 486,
209      'frame': {
210        'y': 5,
211        'height': 20,
212        'x': 1162,
213        'width': 10
214      },
215      'v': true,
216      'stepName': 'Application Launching (43.62ms)',
217      'textMetricsWidth': 156.416015625
218    },
219    {
220      'pid': 3913,
221      'tid': 3913,
222      'itid': 486,
223      'startTs': 5734019791,
224      'dur': 23194270,
225      'startName': 2,
226      'endItid': 486,
227      'frame': {
228        'y': 5,
229        'height': 20,
230        'x': 1171,
231        'width': 6
232      },
233      'v': true
234    },
235    {
236      'pid': 3913,
237      'tid': 3913,
238      'itid': 486,
239      'startTs': 5757214061,
240      'dur': 115679167,
241      'startName': 3,
242      'endItid': 486,
243      'frame': {
244        'y': 5,
245        'height': 20,
246        'x': 1176,
247        'width': 24
248      },
249      'v': true,
250      'stepName': 'UI Ability OnForeground (115.68ms)',
251      'textMetricsWidth': 172.59765625
252    },
253    {
254      'pid': 3913,
255      'tid': 3913,
256      'itid': 486,
257      'startTs': 5872893228,
258      'dur': 62756250,
259      'startName': 4,
260      'frame': {
261        'y': 5,
262        'height': 20,
263        'x': 1199,
264        'width': 14
265      },
266      'v': true,
267      'stepName': 'First Frame - APP Phase (62.76ms)',
268      'textMetricsWidth': 162.9638671875
269    },
270    {
271      'pid': 3913,
272      'tid': 3913,
273      'itid': 17,
274      'startTs': 5968040103,
275      'dur': 29438021,
276      'startName': 5,
277      'frame': {
278        'y': 5,
279        'height': 20,
280        'x': 1219,
281        'width': 7
282      },
283      'v': true
284    }
285  ]);
286
287  let queryProcessSoInitData = sqlit.queryProcessSoInitData;
288  queryProcessSoInitData.mockResolvedValue([
289    {
290      'pid': 3913,
291      'tid': 3913,
292      'itid': 486,
293      'startTs': 5678439061,
294      'dur': 1137500,
295      'soName': ' /system/lib64/seccomp/libapp_filter.z.so',
296      'depth': 0,
297      'frame': {
298        'x': 1160,
299        'y': 0,
300        'width': 1,
301        'height': 20
302      }
303    },
304    {
305      'pid': 3913,
306      'tid': 3913,
307      'itid': 486,
308      'startTs': 5682777082,
309      'dur': 1130729,
310      'soName': ' /system/lib64/libhidebug.so',
311      'depth': 0,
312      'frame': {
313        'x': 1160,
314        'y': 0,
315        'width': 1,
316        'height': 20
317      }
318    },
319    {
320      'pid': 3913,
321      'tid': 3913,
322      'itid': 486,
323      'startTs': 5696226041,
324      'dur': 4319791,
325      'soName': ' system/lib64/extensionability/libinputmethod_extension_module.z.so',
326      'depth': 0,
327      'frame': {
328        'x': 1163,
329        'y': 0,
330        'width': 1,
331        'height': 20
332      }
333    },
334    {
335      'pid': 3913,
336      'tid': 3913,
337      'itid': 486,
338      'startTs': 5700671874,
339      'dur': 4128125,
340      'soName': ' system/lib64/extensionability/libbackup_extension_ability_native.z.so',
341      'depth': 0,
342      'frame': {
343        'x': 1164,
344        'y': 0,
345        'width': 1,
346        'height': 20
347      }
348    },
349    {
350      'pid': 3913,
351      'tid': 3913,
352      'itid': 486,
353      'startTs': 5704894270,
354      'dur': 2187500,
355      'soName': ' system/lib64/extensionability/libwindow_extension_module.z.so',
356      'depth': 0,
357      'frame': {
358        'x': 1165,
359        'y': 0,
360        'width': 1,
361        'height': 20
362      }
363    },
364    {
365      'pid': 3913,
366      'tid': 3913,
367      'itid': 486,
368      'startTs': 5707165624,
369      'dur': 1503125,
370      'soName': ' system/lib64/extensionability/libdatashare_ext_ability_module.z.so',
371      'depth': 0,
372      'frame': {
373        'x': 1165,
374        'y': 0,
375        'width': 1,
376        'height': 20
377      }
378    },
379    {
380      'pid': 3913,
381      'tid': 3913,
382      'itid': 486,
383      'startTs': 5708719791,
384      'dur': 2018229,
385      'soName': ' system/lib64/extensionability/libpush_extension.z.so',
386      'depth': 0,
387      'frame': {
388        'x': 1166,
389        'y': 0,
390        'width': 1,
391        'height': 20
392      }
393    },
394    {
395      'pid': 3913,
396      'tid': 3913,
397      'itid': 486,
398      'startTs': 5710788020,
399      'dur': 846875,
400      'soName': ' system/lib64/extensionability/libenterprise_admin_extension_module.z.so',
401      'depth': 0,
402      'frame': {
403        'x': 1166,
404        'y': 0,
405        'width': 1,
406        'height': 20
407      }
408    },
409    {
410      'pid': 3913,
411      'tid': 3913,
412      'itid': 486,
413      'startTs': 5711693749,
414      'dur': 1522917,
415      'soName': ' system/lib64/extensionability/libstatic_subscriber_extension_module.z.so',
416      'depth': 0,
417      'frame': {
418        'x': 1166,
419        'y': 0,
420        'width': 1,
421        'height': 20
422      }
423    },
424    {
425      'pid': 3913,
426      'tid': 3913,
427      'itid': 486,
428      'startTs': 5713377603,
429      'dur': 1327604,
430      'soName': ' system/lib64/extensionability/libui_extension_module.z.so',
431      'depth': 0,
432      'frame': {
433        'x': 1167,
434        'y': 0,
435        'width': 1,
436        'height': 20
437      }
438    },
439    {
440      'pid': 3913,
441      'tid': 3913,
442      'itid': 486,
443      'startTs': 5714757291,
444      'dur': 2567187,
445      'soName': ' system/lib64/extensionability/libauthorization_extension_module.z.so',
446      'depth': 0,
447      'frame': {
448        'x': 1167,
449        'y': 0,
450        'width': 1,
451        'height': 20
452      }
453    },
454    {
455      'pid': 3913,
456      'tid': 3913,
457      'itid': 486,
458      'startTs': 5717385936,
459      'dur': 2341146,
460      'soName': ' system/lib64/extensionability/libaccessibility_extension_module.z.so',
461      'depth': 0,
462      'frame': {
463        'x': 1167,
464        'y': 0,
465        'width': 1,
466        'height': 20
467      }
468    },
469    {
470      'pid': 3913,
471      'tid': 3913,
472      'itid': 486,
473      'startTs': 5719780728,
474      'dur': 1603646,
475      'soName': ' system/lib64/extensionability/libservice_extension_module.z.so',
476      'depth': 0,
477      'frame': {
478        'x': 1168,
479        'y': 0,
480        'width': 1,
481        'height': 20
482      }
483    },
484    {
485      'pid': 3913,
486      'tid': 3913,
487      'itid': 486,
488      'startTs': 5721437499,
489      'dur': 1314583,
490      'soName': ' system/lib64/extensionability/libworkschedextension.z.so',
491      'depth': 0,
492      'frame': {
493        'x': 1168,
494        'y': 0,
495        'width': 1,
496        'height': 20
497      }
498    }
499  ]);
500  let processData = sqlit.queryProcessData;
501  processData.mockResolvedValue([
502    {
503      cpu: 0, dur: 199000, startTime: 259730000
504    },
505    {
506      cpu: 2, dur: 147000, startTime: 307742000
507    }
508  ]);
509  let processMemData = sqlit.queryProcessMemData;
510  processMemData.mockResolvedValue([
511    {
512      startTime: 593015789,
513      track_id : 153,
514      ts : 30150767408970,
515      type : "measure",
516      value : 0
517    },
518    {
519      startTime: 593360060,
520      track_id : 153,
521      ts : 30150767753241,
522      type : "measure",
523      value : 1
524    }
525  ]);
526  let maxValue = sqlit.queryMemFilterIdMaxValue;
527  maxValue.mockResolvedValue([
528    {
529      filterId: 1,
530      maxValue: 522
531    },
532    {
533      filterId: 2,
534      maxValue: 563
535    }
536  ]);
537  let funcNames = sqlit.queryAllFuncNames;
538  funcNames.mockResolvedValue([
539    {
540      id: 0,
541      name: "test"
542    }
543  ]);
544
545  let soInitNames = sqlit.queryAllSoInitNames;
546  soInitNames.mockResolvedValue([
547    {
548      id: 1,
549      name: "soInitName"
550    }
551  ]);
552
553  let allProcessNames = sqlit.queryAllProcessNames;
554  allProcessNames.mockResolvedValue([
555    {
556      id: 2,
557      name: "processName",
558      pid: 256
559    }
560  ]);
561
562  let srcSlices = sqlit.queryAllSrcSlices;
563  srcSlices.mockResolvedValue([
564    {
565      id: 3,
566      src: "src"
567    }
568  ]);
569
570  let threadNames = sqlit.queryAllThreadName;
571  threadNames.mockResolvedValue([
572    {
573      tid: 4,
574      name: "threadName"
575    }
576  ]);
577
578  spProcessChart.setAttribute = jest.fn();
579  spProcessChart.addChildTraceRow = jest.fn();
580  it('SpProcessChart01', function () {
581    spProcessChart.init();
582    expect(spProcessChart).toBeDefined();
583  });
584
585  it('SpProcessChart02', function () {
586    expect(spProcessChart.initAsyncFuncData()).not.toBeUndefined();
587  });
588
589  it('SpProcessChart03', function () {
590    spProcessChart.initAsyncFuncData();
591    spProcessChart.initDeliverInputEvent();
592    expect(spProcessChart.processAsyncFuncArray.length).toEqual(1);
593  });
594
595  it('SpProcessChart04', function () {
596    let startUpRow = spProcessChart.addStartUpRow(spProcessChart);
597    expect(startUpRow).not.toBeUndefined();
598  });
599
600  it('SpProcessChart05', function () {
601    let soInitRow = spProcessChart.addSoInitRow(spProcessChart, 1);
602    expect(soInitRow).not.toBeUndefined();
603  });
604});
605