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