• 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
16// @ts-ignore
17import { SpHiPerf } from '../../../../dist/trace/component/chart/SpHiPerf.js';
18import {
19  queryHiPerfCpuMergeData2,
20  queryHiPerfEventList,
21  queryPerfThread,
22} from '../../../../src/trace/database/SqlLite.js';
23// @ts-ignore
24import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js';
25const sqlit = require('../../../../dist/trace/database/SqlLite.js');
26jest.mock('../../../../dist/trace/database/SqlLite.js');
27jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
28  return {};
29});
30
31window.ResizeObserver =
32  window.ResizeObserver ||
33  jest.fn().mockImplementation(() => ({
34    disconnect: jest.fn(),
35    observe: jest.fn(),
36    unobserve: jest.fn(),
37  }));
38
39describe('SpHiPerf Test', () => {
40  let queryPerfCmdline = sqlit.queryPerfCmdline;
41  queryPerfCmdline.mockResolvedValue([
42    {
43      report_value:
44        'hiperf record --control prepare -o /data/local/tmp…e sched:sched_waking -a -s dwarf -f 1000 --offcpu',
45    },
46  ]);
47
48  let queryPerfThread = sqlit.queryPerfThread;
49  queryPerfThread.mockResolvedValue([
50    {
51      tid: 2,
52      threadName: 'threadName',
53      pid: 2,
54      processName: 'processName',
55    },
56    {
57      tid: 1,
58      threadName: 'threadName111',
59      pid: 1,
60      processName: 'processNam111e',
61    },
62  ]);
63
64  let queryHiPerfEventList = sqlit.queryHiPerfEventList;
65  queryHiPerfEventList.mockResolvedValue([
66    {
67      id: 0,
68      report_value: 'sched:sched_waking',
69    },
70    {
71      id: 1,
72      report_value: 'sched:sched_switch',
73    },
74  ]);
75
76  let queryHiPerfCpuMergeData2 = sqlit.queryHiPerfCpuMergeData2;
77  queryHiPerfCpuMergeData2.mockResolvedValue([
78    {
79      id: 0,
80      callchain_id: 1,
81      timestamp: 3468360924674,
82      thread_id: 2469,
83      event_count: 1,
84      event_type_id: 0,
85      timestamp_trace: 3468360965799,
86      cpu_id: 2,
87      thread_state: 'Running',
88      startNS: 0,
89    },
90    {
91      id: 4,
92      callchain_id: 1,
93      timestamp: 3468361000799,
94      thread_id: 2469,
95      event_count: 1,
96      event_type_id: 0,
97      timestamp_trace: 3468361041924,
98      cpu_id: 2,
99      thread_state: 'Running',
100      startNS: 76125,
101    },
102    {
103      id: 8,
104      callchain_id: 1,
105      timestamp: 3468361045716,
106      thread_id: 2469,
107      event_count: 1,
108      event_type_id: 0,
109      timestamp_trace: 3468361086841,
110      cpu_id: 2,
111      thread_state: 'Running',
112      startNS: 121042,
113    },
114    {
115      id: 9,
116      callchain_id: 4,
117      timestamp: 3468361054466,
118      thread_id: 1336,
119      event_count: 1,
120      event_type_id: 1,
121      timestamp_trace: 3468361095591,
122      cpu_id: 3,
123      thread_state: 'Suspend',
124      startNS: 129792,
125    },
126  ]);
127  let ss = new SpChartManager();
128  let spHiPerf = new SpHiPerf(ss);
129  it('SpHiPerf01', function () {
130    spHiPerf.init();
131    expect(spHiPerf).toBeDefined();
132  });
133});
134