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