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