• 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 { TabPaneTaskFrames } from '../../../../../../src/trace/component/trace/sheet/task/TabPaneTaskFrames';
17import { SpSystemTrace } from '../../../../../../src/trace/component/SpSystemTrace';
18
19jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => {
20  return {};
21});
22jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {});
23const sqlite = require('../../../../../../src/trace/database/sql/SqlLite.sql');
24jest.mock('../../../../../../src/trace/database/sql/SqlLite.sql');
25const perfSqlite = require('../../../../../../src/trace/database/sql/Perf.sql');
26jest.mock('../../../../../../src/trace/database/sql/Perf.sql');
27jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => {
28  return {};
29});
30jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
31  return {};
32});
33window.ResizeObserver =
34  window.ResizeObserver ||
35  jest.fn().mockImplementation(() => ({
36    disconnect: jest.fn(),
37    observe: jest.fn(),
38    unobserve: jest.fn(),
39  }));
40
41describe('TabPaneTaskFrames Test', () => {
42  let tabPaneTaskFrames = new TabPaneTaskFrames();
43  let mockQueryTaskPoolTotalNum = sqlite.queryTaskPoolTotalNum;
44  mockQueryTaskPoolTotalNum.mockResolvedValue([
45    {
46      tid: 1001,
47    },
48    {
49      tid: 1002,
50    },
51    {
52      tid: 1003,
53    },
54  ]);
55
56  let mockQueryConcurrencyTask = perfSqlite.queryConcurrencyTask;
57  mockQueryConcurrencyTask.mockResolvedValue([
58    {
59      tid: 28573,
60      ipid: 33,
61      funName: 'H:Task Perform: taskId : 2, executeId : 2',
62      startTs: 26020542893000,
63      dur: 4999979000,
64      id: 310,
65      priority: 1,
66      allocationTaskRow: 294,
67      executeTaskRow: 310,
68      returnTaskRow: 785,
69      executeId: 2,
70    },
71    {
72      tid: 28599,
73      ipid: 33,
74      funName: 'H:Task Perform: taskId : 3, executeId : 3',
75      startTs: 26020550419000,
76      dur: 5001432000,
77      id: 321,
78      priority: 1,
79      allocationTaskRow: 297,
80      executeTaskRow: 321,
81      returnTaskRow: 797,
82      executeId: 3,
83    },
84    {
85      tid: 28600,
86      ipid: 33,
87      funName: 'H:Task Perform: taskId : 4, executeId : 4',
88      startTs: 26020550826000,
89      dur: 5001023000,
90      id: 331,
91      priority: 1,
92      allocationTaskRow: 300,
93      executeTaskRow: 331,
94      returnTaskRow: 799,
95      executeId: 4,
96    },
97  ]);
98
99  SpSystemTrace.DATA_TASK_POOL_CALLSTACK = new Map();
100  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(87, {
101    id: 87,
102    ts: 26015536047000,
103    dur: 168000,
104    callid: 63,
105    cat: null,
106    identify: 7,
107    name: 'H:Task Allocation: taskId : 1, executeId : 1, priority : 1, executeState : 1',
108    depth: 3,
109    cookie: null,
110    parent_id: 86,
111    argsetid: null,
112    chainId: null,
113    spanId: null,
114    parentSpanId: null,
115    flag: null,
116    args: null,
117  });
118  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(99, {
119    id: 99,
120    ts: 26015539134000,
121    dur: 5001738000,
122    callid: 111,
123    cat: null,
124    identify: 10,
125    name: 'H:Task Perform: taskId : 1, executeId : 1',
126    depth: 1,
127    cookie: null,
128    parent_id: 95,
129    argsetid: null,
130    chainId: null,
131    spanId: null,
132    parentSpanId: null,
133    flag: null,
134    args: null,
135  });
136  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(292, {
137    id: 292,
138    ts: 26020541020000,
139    dur: 2526000,
140    callid: 63,
141    cat: null,
142    identify: 15,
143    name: 'H:Task PerformTask End: taskId : 1, executeId : 1, performResult : IsCanceled',
144    depth: 1,
145    cookie: null,
146    parent_id: 291,
147    argsetid: null,
148    chainId: null,
149    spanId: null,
150    parentSpanId: null,
151    flag: null,
152    args: null,
153  });
154  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(294, {
155    id: 294,
156    ts: 26020541698000,
157    dur: 44000,
158    callid: 63,
159    cat: null,
160    identify: 7,
161    name: 'H:Task Allocation: taskId : 2, executeId : 2, priority : 1, executeState : 1',
162    depth: 3,
163    cookie: null,
164    parent_id: 293,
165    argsetid: null,
166    chainId: null,
167    spanId: null,
168    parentSpanId: null,
169    flag: null,
170    args: null,
171  });
172  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(297, {
173    id: 297,
174    ts: 26020541828000,
175    dur: 196000,
176    callid: 63,
177    cat: null,
178    identify: 7,
179    name: 'H:Task Allocation: taskId : 3, executeId : 3, priority : 1, executeState : 1',
180    depth: 3,
181    cookie: null,
182    parent_id: 295,
183    argsetid: null,
184    chainId: null,
185    spanId: null,
186    parentSpanId: null,
187    flag: null,
188    args: null,
189  });
190  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(300, {
191    id: 300,
192    ts: 26020542123000,
193    dur: 572000,
194    callid: 63,
195    cat: null,
196    identify: 7,
197    name: 'H:Task Allocation: taskId : 4, executeId : 4, priority : 1, executeState : 1',
198    depth: 3,
199    cookie: null,
200    parent_id: 298,
201    argsetid: null,
202    chainId: null,
203    spanId: null,
204    parentSpanId: null,
205    flag: null,
206    args: null,
207  });
208  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(310, {
209    id: 310,
210    ts: 26020542893000,
211    dur: 4999979000,
212    callid: 111,
213    cat: null,
214    identify: 10,
215    name: 'H:Task Perform: taskId : 2, executeId : 2',
216    depth: 1,
217    cookie: null,
218    parent_id: 309,
219    argsetid: null,
220    chainId: null,
221    spanId: null,
222    parentSpanId: null,
223    flag: null,
224    args: null,
225  });
226  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(321, {
227    id: 321,
228    ts: 26020550419000,
229    dur: 5001432000,
230    callid: 152,
231    cat: null,
232    identify: 10,
233    name: 'H:Task Perform: taskId : 3, executeId : 3',
234    depth: 1,
235    cookie: null,
236    parent_id: 320,
237    argsetid: null,
238    chainId: null,
239    spanId: null,
240    parentSpanId: null,
241    flag: null,
242    args: null,
243  });
244  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(331, {
245    id: 331,
246    ts: 26020550826000,
247    dur: 5001023000,
248    callid: 153,
249    cat: null,
250    identify: 10,
251    name: 'H:Task Perform: taskId : 4, executeId : 4',
252    depth: 1,
253    cookie: null,
254    parent_id: 329,
255    argsetid: null,
256    chainId: null,
257    spanId: null,
258    parentSpanId: null,
259    flag: null,
260    args: null,
261  });
262  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(785, {
263    id: 785,
264    ts: 26025543022000,
265    dur: 30000,
266    callid: 63,
267    cat: null,
268    identify: 4,
269    name: 'H:Task PerformTask End: taskId : 2, executeId : 2, performResult : Successful',
270    depth: 1,
271    cookie: null,
272    parent_id: 784,
273    argsetid: null,
274    chainId: null,
275    spanId: null,
276    parentSpanId: null,
277    flag: null,
278    args: null,
279  });
280  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(797, {
281    id: 797,
282    ts: 26025551976000,
283    dur: 28000,
284    callid: 63,
285    cat: null,
286    identify: 4,
287    name: 'H:Task PerformTask End: taskId : 3, executeId : 3, performResult : Successful',
288    depth: 1,
289    cookie: null,
290    parent_id: 794,
291    argsetid: null,
292    chainId: null,
293    spanId: null,
294    parentSpanId: null,
295    flag: null,
296    args: null,
297  });
298  SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(799, {
299    id: 799,
300    ts: 26025552025000,
301    dur: 13000,
302    callid: 63,
303    cat: null,
304    identify: 4,
305    name: 'H:Task PerformTask End: taskId : 4, executeId : 4, performResult : Successful',
306    depth: 1,
307    cookie: null,
308    parent_id: 798,
309    argsetid: null,
310    chainId: null,
311    spanId: null,
312    parentSpanId: null,
313    flag: null,
314    args: null,
315  });
316
317  it('TabPaneTaskFrames Test01', function () {
318    TabPaneTaskFrames.TaskArray = [
319      {
320        startTs: 5628901000,
321        dur: 4999979000,
322        funName: 'H:Task Perform: taskId : 2, executeId : 2',
323        argsetid: null,
324        depth: 1,
325        id: 310,
326        frame: {
327          x: 526,
328          y: 20,
329          width: 469,
330          height: 20,
331        },
332        textMetricsWidth: 185.634765625,
333      },
334      {
335        startTs: 5627706000,
336        dur: 44000,
337        funName: 'H:Task Allocation: taskId : 2, executeId : 2, priority : 1, executeState : 1',
338        argsetid: null,
339        depth: 3,
340        id: 294,
341        frame: {
342          x: 526,
343          y: 60,
344          width: 1,
345          height: 20,
346        },
347      },
348      {
349        startTs: 10629030000,
350        dur: 30000,
351        funName: 'H:Task PerformTask End: taskId : 2, executeId : 2, performResult : Successful',
352        argsetid: null,
353        depth: 1,
354        id: 785,
355        frame: {
356          x: 995,
357          y: 20,
358          width: 1,
359          height: 20,
360        },
361      },
362    ];
363
364    tabPaneTaskFrames.taskFramesTbl = jest.fn(() => true);
365    tabPaneTaskFrames.taskFramesTbl!.recycleDataSource = jest.fn(() => true);
366    let frameData = {};
367    tabPaneTaskFrames.data = frameData;
368    expect(tabPaneTaskFrames.data).toBeUndefined();
369  });
370
371  it('TabPaneTaskFrames Test02', function () {
372    TabPaneTaskFrames.TaskArray = [];
373    let mockQueryTaskListByExecuteTaskIds = sqlite.queryTaskListByExecuteTaskIds;
374    mockQueryTaskListByExecuteTaskIds.mockResolvedValue([
375      {
376        ipid: 33,
377        allocationTaskRow: 294,
378        executeTaskRow: 310,
379        returnTaskRow: 785,
380        executeId: 2,
381        priority: 1,
382      },
383      {
384        ipid: 36,
385        allocationTaskRow: 300,
386        executeTaskRow: 331,
387        returnTaskRow: 799,
388        executeId: 4,
389        priority: 1,
390      },
391    ]);
392    let frameData1 = {
393      recordStartNs: 26014913992000,
394      leftNs: 7957675110,
395      rightNs: 8705376127,
396      taskFramesData: [
397        {
398          startTs: 5628901000,
399          dur: 4999979000,
400          funName: 'H:Task Perform: taskId : 2, executeId : 2',
401          argsetid: null,
402          depth: 1,
403          id: 310,
404          itid: 111,
405          ipid: 33,
406          frame: {
407            x: 526,
408            y: 20,
409            width: 469,
410            height: 20,
411          },
412          textMetricsWidth: 185.634765625,
413          tid: 28573,
414        },
415        {
416          startTs: 5636834000,
417          dur: 5001023000,
418          funName: 'H:Task Perform: taskId : 4, executeId : 4',
419          argsetid: null,
420          depth: 1,
421          id: 331,
422          itid: 153,
423          ipid: 33,
424          frame: {
425            x: 527,
426            y: 20,
427            width: 469,
428            height: 20,
429          },
430          textMetricsWidth: 185.634765625,
431          tid: 28600,
432        },
433      ],
434    };
435    tabPaneTaskFrames.taskFramesTbl = jest.fn(() => true);
436    tabPaneTaskFrames.taskFramesTbl!.recycleDataSource = jest.fn(() => true);
437    tabPaneTaskFrames.data = frameData1;
438    expect(tabPaneTaskFrames.data).toBeUndefined();
439  });
440
441  it('TabPaneTaskFrames Test03', function () {
442    TabPaneTaskFrames.TaskArray = [];
443    let frameData = {
444      recordStartNs: 26014913992000,
445      leftNs: 96132987,
446      rightNs: 2563546344,
447      taskFramesData: [
448        {
449          startTs: 625142000,
450          dur: 5001738000,
451          funName: 'H:Task Perform: taskId : 1, executeId : 1',
452          argsetid: null,
453          depth: 1,
454          id: 99,
455          itid: 111,
456          ipid: 33,
457          frame: {
458            x: 58,
459            y: 20,
460            width: 469,
461            height: 20,
462          },
463          textMetricsWidth: 185.634765625,
464          tid: 28573,
465        },
466      ],
467    };
468    let mockQueryTaskListByExecuteTaskIds = sqlite.queryTaskListByExecuteTaskIds;
469    mockQueryTaskListByExecuteTaskIds.mockResolvedValue([
470      {
471        allocationTaskRow: 87,
472        executeTaskRow: 99,
473        returnTaskRow: 292,
474        executeId: 1,
475        priority: 1,
476      },
477    ]);
478    tabPaneTaskFrames.taskFramesTbl = jest.fn(() => true);
479    tabPaneTaskFrames.taskFramesTbl!.recycleDataSource = jest.fn(() => true);
480    tabPaneTaskFrames.data = frameData;
481    expect(tabPaneTaskFrames.data).toBeUndefined();
482  });
483
484  it('TabPaneTaskFrames Test04', function () {
485    TabPaneTaskFrames.TaskArray = [
486      {
487        startTs: 10628950000,
488        dur: 49911000,
489        funName: 'H:Task Perform: taskId : 6, executeId : 8',
490        argsetid: null,
491        depth: 1,
492        id: 782,
493        frame: {
494          x: 710,
495          y: 20,
496          width: 304,
497          height: 20,
498        },
499        tid: 28573,
500        textMetricsWidth: 185.634765625,
501      },
502      {
503        startTs: 6631912000,
504        dur: 74000,
505        funName: 'H:Task Allocation: taskId : 6, executeId : 8, priority : 0, executeState : 1',
506        argsetid: null,
507        depth: 2,
508        id: 372,
509        frame: {
510          x: 620,
511          y: 40,
512          width: 1,
513          height: 20,
514        },
515      },
516      {
517        startTs: 10679004000,
518        dur: 56000,
519        funName: 'H:Task PerformTask End: taskId : 6, executeId : 8, performResult : Successful',
520        argsetid: null,
521        depth: 1,
522        id: 806,
523        frame: {
524          x: 999,
525          y: 20,
526          width: 1,
527          height: 20,
528        },
529      },
530    ];
531    TabPaneTaskFrames.IsShowConcurrency = true;
532    tabPaneTaskFrames.taskFramesTbl = jest.fn(() => true);
533    tabPaneTaskFrames.taskFramesTbl!.recycleDataSource = jest.fn(() => true);
534    let frameData = {};
535    tabPaneTaskFrames.data = frameData;
536    expect(tabPaneTaskFrames.data).toBeUndefined();
537  });
538
539  it('TabPaneTaskFrames Test05', function () {
540    tabPaneTaskFrames.taskFramesTbl = jest.fn(() => true);
541    tabPaneTaskFrames.taskFramesTbl!.recycleDataSource = jest.fn(() => true);
542    expect(tabPaneTaskFrames.sortByColumn({ sort: 1, key: 'taskPriority' })).toBeUndefined();
543  });
544});
545