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 { SpSystemTrace } from '../SpSystemTrace'; 17import { TraceRow } from '../trace/base/TraceRow'; 18import { renders } from '../../database/ui-worker/ProcedureWorker'; 19import { HiSysEventRender, HiSysEventStruct } from '../../database/ui-worker/ProcedureWorkerHiSysEvent'; 20import { hiSysEventDataSender } from '../../database/data-trafic/HiSysEventDataSender'; 21import { queryHiSysEventData } from '../../database/sql/Perf.sql'; 22 23export class SpHiSysEventChart { 24 private trace: SpSystemTrace; 25 26 constructor(trace: SpSystemTrace) { 27 this.trace = trace; 28 } 29 30 async init(): Promise<void> { 31 let hiSysEventData = await queryHiSysEventData(); 32 if (hiSysEventData.length === 0) { 33 return; 34 } 35 let eventRow = await this.initRow(); 36 this.trace.rowsEL?.appendChild(eventRow); 37 } 38 39 async initRow(): Promise<TraceRow<HiSysEventStruct>> { 40 let hiSysEventRow = TraceRow.skeleton<HiSysEventStruct>(); 41 hiSysEventRow.rowParentId = ''; 42 hiSysEventRow.rowId = 'Hisysevent'; 43 hiSysEventRow.rowType = TraceRow.ROW_TYPE_HI_SYSEVENT; 44 hiSysEventRow.name = 'Hisysevent'; 45 hiSysEventRow.style.width = '100%'; 46 hiSysEventRow.style.height = '40px'; 47 hiSysEventRow.setAttribute('height', '40px'); 48 hiSysEventRow.setAttribute('children', ''); 49 hiSysEventRow.supplierFrame = (): Promise<HiSysEventStruct[]> => { 50 return hiSysEventDataSender(hiSysEventRow).then((res) => { 51 return res; 52 }); 53 }; 54 hiSysEventRow.addTemplateTypes('HiSysEvent'); 55 hiSysEventRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 56 hiSysEventRow.selectChangeHandler = this.trace.selectChangeHandler; 57 hiSysEventRow.onThreadHandler = (useCache: boolean): void => { 58 let context: CanvasRenderingContext2D; 59 if (hiSysEventRow.currentContext) { 60 context = hiSysEventRow.currentContext; 61 } else { 62 context = hiSysEventRow.collect ? this.trace.canvasFavoritePanelCtx! : this.trace.canvasPanelCtx!; 63 } 64 hiSysEventRow!.canvasSave(context); 65 (renders.hiSysEvent as HiSysEventRender).renderMainThread( 66 { 67 context: context, 68 useCache: useCache, 69 type: 'hisys_event', 70 }, 71 hiSysEventRow! 72 ); 73 hiSysEventRow!.canvasRestore(context, this.trace); 74 }; 75 return hiSysEventRow; 76 } 77} 78